Installing target java version in ant javac

I need to compile a jar file using ant (1.7.0) to run under a specific version of Java (1.5). I currently have Java 1.6 on my machine. I tried setting:

<target name="compile"> <javac compiler="javac1.5" target="1.5" srcdir=.../> </target> 

I also deleted

 <property name="build.compiler" value="modern"/> 

and there is no properties file. I am running Java 1.6 on Linux / SUSE

There is also an easy way to determine which version of Java is expected in the jar file.

+57
javac ant
Sep 28 '09 at 16:23
source share
4 answers

Use the target attribute and remove the compiler attribute. See here . Therefore, it should look something like this:

 <target name="compile"> <javac target="1.5" srcdir=.../> </target> 

Hope this helps

+81
Sep 28 '09 at 16:29
source share

You must specify the source and target. I recommend providing ant defaults , so you don't need to specify the source / target attribute for each javac task:

 <property name="ant.build.javac.source" value="1.5"/> <property name="ant.build.javac.target" value="1.5"/> 

See Java cross-compilation notes for more details.

+36
May 24 '13 at 19:28
source share

To find the java version in the class files I used:

 javap -verbose <classname> 

which announces the version at the beginning as

 minor version: 0 major version: 49 

which corresponds to Java 1.5

+14
Sep 28 '09 at 16:38
source share

You can also set the {{ant.build.javac.target=1.5}} ant property to update the target of the default task. See http://ant.apache.org/manual/javacprops.html#target

+5
09 Oct '12 at 11:24
source share



All Articles