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

后端 未结 24 888
北恋
北恋 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:12

    I was facing the same problem, making the executable property in the javac tag to be set to the location of javac.exe resolved the problem for me. This resolved the problem

    <javac srcdir="${srcDir}" destdir="${buildDir}" fork="true" executable="C:\Program Files\Java\jdk1.7.0_03\bin\javac"/>
    
    0 讨论(0)
  • 2020-12-07 17:14

    I hope you are aware about System and User environmental variables. The user ones are preferred over system. If you have set your JAVA_HOME in system variables and if there is an entry for the same in user variables, then you will get the latter one only.

    Right click on My computer, Go to properties, Select Advanced tab and click on Environmental variables to see the list of user and system environment variables.

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

    Make sure you do not use the trailing semicolon: This will not work:

    set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_29;
    

    This will:

    set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_29
    
    0 讨论(0)
  • 2020-12-07 17:16

    When you say you have "clearly set" JAVA_HOME to "C:\Program Files\Java\jdk1.6.0_14" - is that what you see when you run "set" from the command line? I believe Ant will guess at a value for JAVA_HOME if one isn't set at all... is it possible that you've set JAVAHOME instead of JAVA_HOME?

    If it's nothing like that, I suggest you edit the ant.bat batch file (and whatever it calls - I can't remember whether it's convoluted or not offhand) to print out JAVA_HOME at the start and at various other interesting places.

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

    In eclipse set the installed JRE setting to the JDK - in the project (project properties -> Java Build Path-> Libraries), or global default in preferences (Java->Installed JREs). The eclispe setting is stronger than the system variable.

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

    When everything else is correct try the following

    1. Goto Window -> Preferences -> Ant -> Runtime -> ClassPath
    2. Expand Global Entries and check jdk tools available here.
    3. Add the required tools.jar from a specific version of java such as "C:\Program Files\Java\jdk1.6.0_45\lib\tools.jar"
    4. Now build and check the results.

    Note: Add tools.jar for the java compiler that you want to use and give preference to it by moving it up in the list of tools.jar when multiple tools.jar (java compilers) are present.

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