Ant is using wrong java version

前端 未结 16 1387
小蘑菇
小蘑菇 2020-11-28 09:20

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.

相关标签:
16条回答
  • 2020-11-28 10:08

    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

    0 讨论(0)
  • 2020-11-28 10:13

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

    0 讨论(0)
  • 2020-11-28 10:16

    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>
    
    0 讨论(0)
  • 2020-11-28 10:17

    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.

    0 讨论(0)
  • 2020-11-28 10:19

    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.

    0 讨论(0)
  • 2020-11-28 10:19

    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.

    0 讨论(0)
提交回复
热议问题