Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the target version of Java in ant javac

Tags:

javac

ant

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 have tried setting:

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

I have also removed

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

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

Also is there a simple way of determining which version of Java is expected in the jar file.

like image 862
peter.murray.rust Avatar asked Sep 28 '09 16:09

peter.murray.rust


People also ask

What version of Java does Ant use?

Which version of Java is required to run Apache Ant? You will need Java installed on your system, version 1.8 or later required. The later the version of Java, the more Ant tasks you get. The git branch 1.9.

What is javac source and target?

You use the -source option to specify the java version used for compilation and you use the -target option to specify the lowest java version to support. eg. If I specify a target of 1.4, then my program will not be able to run on java 1.3 or lower. see the following javac documentation for more info.

How do I check Ant version?

Check your installation by opening a command line and typing ant -version into the commend line. The system should find the command ant and show the version number of your installed Ant version.


2 Answers

Use "target" attribute and remove the 'compiler' attribute. See here. So it should go something like this:

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

Hope this helps

like image 168
NawaMan Avatar answered Oct 03 '22 17:10

NawaMan


Both source and target should be specified. I recommend providing ant defaults, that way you do not need to specify source/target attribute for every javac task:

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

See Java cross-compiling notes for more information.

like image 25
user1338062 Avatar answered Oct 03 '22 19:10

user1338062