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

后端 未结 24 885
北恋
北恋 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 16:52

    Just set the JDK path from the below steps:

    1. Go to 'Run' ->External Tools -> External Tools Configuration

    2. -> Select 'JRE' Then from the DropDown list select the available JDK . ex. jdk1.8.0_25

    0 讨论(0)
  • 2020-12-07 16:55

    I faced this problem when building my project with Jenkins. First, it could not find ant.bat, which was fixed by adding the path to ant.bat to the system environment variable path. Then ant could not find the jdk directory. This was fixed by right-clicking on my computer > properties > advanced > environment variables and creating a new environment variable called JAVA_HOME and assigning it a value of C:\Program Files\Java\jdk1.7.0_21. Don't create this environment variable in User Variables. Create it under System Variables only.
    In both cases, I had to restart the system.

    0 讨论(0)
  • 2020-12-07 16:56

    I have met the similiar issue. I would link to run Ant task fron Maven build and I got the issue. I have fixed it as bellow steps:

    • Make sure JAVA_HOME is set right. You can check it on Windowns in command line as: C:>echo %JAVA_HOME% Result would look like: C:\Progra~1\Java\jdk1.6.0_30\
    • Copy file tools.jar from %JAVA_HOME%\lib to lib directory of Maven.

    And it worked for me.

    0 讨论(0)
  • 2020-12-07 16:56

    If you have JAVA_HOME set but there's a typo in it, you will also see the bogus reference to a jre6 path.

    0 讨论(0)
  • 2020-12-07 16:56

    Quick work around for the same is

    Copy C:\Program Files\Java\jdk1.6.0_14\lib\tools.jar to C:\Program Files\Java\jre6\lib\

    This exception is coming because JAVA_HOME is being set as C:\Program Files\Java\jre6 and Ant is not able to find tools.jar in it.

    0 讨论(0)
  • 2020-12-07 16:57

    The semicolon was throwing me off: I had JAVA_HOME set to "C:\jdk1.6.0_26;" instead of "C:\jdk1.6.0_26". I removed the trailing semicolon after following Jon Skeet's suggestion to examine the ant.bat file. This is part of that file:

    if "%JAVA_HOME%" == "" goto noJavaHome
    if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
    

    So the semi-colon wasn't being trimmed off the end, causing this to fail to find the file, therefore defaulting to "C:\Java\jre6" or something like that.

    The confusing part is that the HowtoBuild page states to use the semi-colon, but that seems to break it.

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