Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant is using wrong java version

Tags:

java

ant

People also ask

Which version of Java does Ant use?

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. x is used for long term support of Ant 1.9.

Is Ant compatible with Java 11?

13 and 1.10. 5 Released, Supports Java 11 Single-file Source Programs.

How do I mention Java version in build XML?

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.

How do I change my current version of Java?

In the Java Control Panel, click on the Java tab. Verify that the latest Java Runtime version is enabled by checking the Enabled box. Click OK in Java Control Panel window to confirm changes and close the window. Try to run same applet and verify it is now running using latest version of Java installed in your system.


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.


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.


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.


Run ant in verbose mode : ant -v and looks for clues.


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.

<javac compiler="classic" taskname="javac" includeAntRuntime="no" fork=" deprecation="true" target="1.4" source="1.4" srcdir="${src}" destdir="${classes}">

Note: The 'srcdir' and 'destdir' are property values set else where in the build script, e.g. <property name="classes" value="c:/classes" />