I'm using Ant 1.7.0 and installed java 1.6 which is in JAVA_HOME.
I want to build a project using java 1.5, so I've exported JAVA_HOME to be my java 1.5 directory.
java -version
says "1.5". When I run Ant it uses java 1.6.
|
|
Just had this issue, it happened because I'd first added the build file to the ant-view when the default JRE was 1.6. There was no project-specific JRE and I changed the default to 1.5, even eclipse was running in 1.5, and JAVA_HOME was 1.5 too. Running the ant target from the command line used JRE 1.5, but within eclipse it still used 1.6. I had to right-click the ant target, select Run As... and change the JRE under the JRE tab. This setting is remembered for subsequent runs. |
|||||||||||||
|
|
Easy! In Eclipse:
Re-run the task, it should be fine now. |
|||||
|
|
According to the ant manual, setting JAVA_HOME should work - are you sure the changed setting is visible to ant? Alternatively, you could use the JAVACMD variable. |
|||||
|
|
You can use the target and source properties on the javac tag to set a target runtime. The example below will compile any source code to target version 1.4 on any compiler that supports version 1.4 or later.
Note: The 'srcdir' and 'destdir' are property values set else where in the build script,
e.g. |
||||
|
|
|
Run ant in verbose mode : |
|||||
|
|
You could achieve that with following steps, if you are using Eclipse IDE:
|
||||
|
|
|
You can also specify in a javac task what level of compatibility ( 1.4, 1.5, 1.6 ) you want to use, you can set the "source" and "target" level values, check the docs here : Javac task documentation |
|||||
|
|
This is rather an old question, but I will add my notes for future references. I had a similar issue and fixed it by changing the order of the exports in the PATH variable. For example I was using a method of concatenating strings to my PATH by doing (this is just an example):
If my variable PATH already had a java in it, the last value would be meaningless, thus the order would matter. To solve this I started inverting it by adding my variable first, then adding the PATH. Following this idea I inverted the order that ANT_HOME was being exported. Adding JAVA_HOME before ANT_HOME. This could be just a coincidence, but it worked for me. |
|||||
|
|
If you are not using eclipse. Then you can change the ant java property directly on the file as mentioned here. http://pissedoff-techie.blogspot.in/2014/09/ant-picks-up-incorrect-java-version.html |
|||||
|
|
If you run Ant from eclipse, the eclipse will use jdk or jre that is configured in the class-path(build path). |
|||||||||||||||||
|
|
Use the following 2 properties for
Explaination of the properties can be found here |
||||
|
|
|
Build file:
Output:
|
|||
|
|