Setting JAVA_HOME when running Ant from Java

后端 未结 5 465
生来不讨喜
生来不讨喜 2021-01-03 04:27

The reason is long and boring, but I need to run an Ant script to compile Java 1.5 code from a Java 1.4 app. I keep getting this error, though:

BUILD FAILED         


        
相关标签:
5条回答
  • 2021-01-03 05:08

    Shouldn't the backslashes be doubled?

    p.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.6.0_04");
    
    0 讨论(0)
  • 2021-01-03 05:10

    Another way to make this work is to add 'tools.jar' to your classpath. The javac compiler is contained within this jar.

    java -cp $JAVA_HOME/lib/tools.jar ...

    0 讨论(0)
  • 2021-01-03 05:17

    Have you set environment variables JAVA_HOME and ANT_HOME properly? If you are setting via code it should work though.

    Also check if your %JAVA_HOME%\bin directory %ANT_HOME%\bin should be in the environment variable 'path'.

    Your problem seems to be with the %JAVA_HOME%\bin not being present in the envt. variable path though.

    0 讨论(0)
  • 2021-01-03 05:17

    javac option is available in tools.jar. In eclipse, even if your JRE HOME points to a jdk, all the system libraries point to JDK_HOME\jre\lib. There is no tools.jar. You can add tools.jar as an external Jar file. This should solve your issue

    0 讨论(0)
  • 2021-01-03 05:30

    Does the javac task in your buildfile have fork="yes"? If not, then it doesn't matter what the java.home property is set to; ant will attempt to call the javac Main method in the same java process, which from your error is a JRE, not a JDK.

    EDIT Try setting the executable property of your javac task to the full path to the javac binary and add compiler="extJavac" to the task.

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