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.
You could achieve that with following steps, if you are using Eclipse IDE:
Right click on the task in your ant build file (build.xml
).
Mouse over "Run As", click on "External Tool Configurations...".
Add followings to "Arguments":
-Dant.build.javac.target=1.5 -Dant.build.javac.source=1.5
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
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).