Why does ANT tell me that JAVA_HOME is wrong when it is not?

后端 未结 24 887
北恋
北恋 2020-12-07 16:49

I get the error:

C:\\dev\\ws\\springapp\\build.xml:81: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not

相关标签:
24条回答
  • 2020-12-07 17:06

    had the same problem;

    c:\jb\src\build.xml:191: Unable to find a javac compiler;
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK.
    It is currently set to "C:\Program Files\Java\jre7"
    
    Total time: 0 seconds
    
    c:\jb\src>echo %JAVA_HOME%
    c:\Program Files\Java\jdk1.7.0_13
    

    solution:

    path = c:\ant\bin\;%PATH%
    path = c:\Program Files\Java\jdk1.7.0_17\bin;%PATH%
    set "JAVA_HOME=c:\Program Files\Java\jdk1.7.0_13"
    

    I guess the jdk path instruction alone would do it but I'm to lazy to figure it out above solution is bullet proof. :-)

    Also using Windows7

    0 讨论(0)
  • 2020-12-07 17:08
    1. In Eclipse click RunExternal ToolsExternal Tools Configurations.
    2. Click the JRE tab.
    3. Click the Installed JREs... button.
    4. Click the Add button.
      (Select Standard VM, where applicable.)
    5. Click the Directory button.
    6. Browse to your JDK version (not JRE) of your installed Java
      (e.g. C:\Program Files\Java\jdk1.7.0_04).
    7. Click Finish and OK.
    8. Select the JDK at Separate JRE and click Close.
    9. Re-run your Ant script — have fun!

    This worked in a particular scenario I encountered.

    0 讨论(0)
  • 2020-12-07 17:08

    I encountered the same problem when I try to run Ant build using the following command:

    java -cp ant.jar:ant-launcher.jar org.apache.tools.ant.Main
    

    The output of the command is:

    BUILD FAILED
    XXX/build.xml:8: Unable to find a javac compiler;
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK.
    It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
    

    It seems the java executable is picking "/usr/lib/jvm/java-6-openjdk/jre" as JAVA_HOME, as opposed to "/usr/lib/jvm/java-6-openjdk" where JDK is installed.

    I resolved this issue by setting fork="yes" in my <javac> task.

    Take a look at: http://ant.apache.org/manual/Tasks/javac.html

    0 讨论(0)
  • 2020-12-07 17:08

    If need to run ant in eclipse with inbuilt eclipse jdk add the below line in build.xml

    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    
    0 讨论(0)
  • 2020-12-07 17:09

    I had the same problem. My JDK package pointed by JAVA_HOME didn't have any tools.jar Be sure that your JDK instal.lation has tools.jar

    (clearly the message error is confusing)

    0 讨论(0)
  • 2020-12-07 17:11

    To solve this problem add tools.jar file in window->preferences->ant-> runtime .

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