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.
Use the following 2 properties for javac tag:
fork="yes"
executable="full-path-to-the-javac-you-want-to-use".
Explaination of the properties can be found here
Run ant in verbose mode : ant -v and looks for clues.
Set your JAVA_HOME environment variable with the required java version (in your case java 1.5), then in build.xml use executable="${JAVA_HOME}/bin/javac" inside <javac></javac> tag .
example:
<target name="java compiler" description="Compiles the java code">
<javac executable="${JAVA_HOME}/bin/javac" srcdir="./src"
destdir="${build.dir}/classes">
</javac>
</target>
According to the Ant Documentation, set JAVACMD environment variable to complete path to java.exe of the JRE version that you want to run Ant under.
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.
By default the Ant will considered the JRE as the workspace JRE version. You need to change according to your required version by following the below.
In Eclipse:
Right click on your build.xml click "Run As", click on "External Tool Configurations..." Select tab JRE.
Select the JRE you are using.
Re-run the task, it should be fine now.