tags:

views:

457

answers:

9

Hi to All : I have used Collections in my code with Generics. When try to compile that java file in build.xml, its showing error at generics and its saying its not a statement. I am using Apache-Ant-1.6.5 and i have installed JDK 1.5 only . I know generic will support in jdk1.5 but its showing error. The below is the error i am getting for the code

code :

Map<String, String> inputconfigmap = 
    new LinkedHashMap<String, String>();

Exception :

compile:
    [mkdir] Created dir: D:\GenericPreProcessor\Source\classes
    [javac] Compiling 49 source files to D:\GenericPreProcessor\Source\classes
    [javac] D:\GenericPreProcessor\Source\src\com\dnb\genericpreprocessor\fileprocessor\FixedLength
FileProcessor.java:187: not a statement
    [javac] Map<String, String> inputconfigmap = 
                new LinkedHashMap<String, String>();
+1  A: 

Maybe you can check the version of your compilator with :

<echo>JVM version is ${ant.java.version}</echo>
<echo>Target compilation is ${ant.build.javac.target}</echo>

And you can add <property name="ant.build.javac.target" value="1.5" /> to force the compiler to use Java 5 compliance... This property is the default target from ant 1.7, for ant 1.6 I think you must add target="${ant.build.javac.target}" to your javac target.

Vinze
A: 

You need to define the type of the Map, i.e:

Map<String, String> inputconfigmap  = new LinkedHashMap<String, String>();
kgiannakakis
A: 

Try

Map<?, ?> inputconfigmap = new LinkedHashMap<?, ?>();
Drejc
+2  A: 

Have you tried explicitly setting the source and target attributes for your javac task?

<target name="compile">
    <javac .....
        source="1.6"
        target="1.6" />
</target>
toolkit
A: 

Hi I have given String,String in angle brackets n tried but it is still showing the same error..Please help me.

raja
A: 

Hi ToolKit:
Sorry i dont get you. can you explain little bit more?

raja
see my update...
toolkit
A: 

Are you using double angle brackets (<< and >>)? They should be single ones as kgiannakakis showed:

Map<String, String> inputconfigmap  = new LinkedHashMap<String, String>();
tehvan
A: 

Hi Vinze :
I did as per your suggestion but i got the following in the console.

Console :
D:\GenericPreProcessor\Source>ant
Buildfile: build.xml
[echo] JVM version is 1.5
[echo] Target compilation is ${ant.build.javac.target}

clean:
[delete] Deleting directory D:\GenericPreProcessor\Source\classes

cleanJar:

compile:
[mkdir] Created dir: D:\GenericPreProcessor\Source\classes
[javac] Compiling 49 source files to D:\GenericPreProcessor\Source\classes
[javac] javac: invalid target release: 1.5
[javac] Usage: javac
[javac] where possible options include:
[javac] -g Generate all debugging info
[javac] -g:none Generate no debugging info
[javac] -g:{lines,vars,source} Generate only some debugging info
[javac] -nowarn Generate no warnings
[javac] -verbose Output messages about what the compiler is doing
[javac] -deprecation Output source locations where deprecated APIs are used
[javac] -classpath Specify where to find user class files
[javac] -sourcepath Specify where to find input source files
[javac] -bootclasspath Override location of bootstrap class files
[javac] -extdirs Override location of installed extensions
[javac] -d Specify where to place generated class files
[javac] -encoding Specify character encoding used by source files
[javac] -source Provide source compatibility with specified release
[javac] -target Generate class files for specific VM version
[javac] -help Print a synopsis of standard options

BUILD FAILED

raja
weird... the "JVM version is 1.5" and "invalid target release: 1.5"... did you look at the link gave by toolkit http://stackoverflow.com/questions/520168/doubt-in-build-xml-file-in-apache-ant1-6-5/520223#520223
Vinze
A: 

Hi tehvan :

I have used single angle brackets only in the code.

raja