Why does ANT tell me that JAVA_HOME is wrong when it is not?
Solution 1:
- In Eclipse click Run → External Tools → External Tools Configurations.
- Click the JRE tab.
- Click the Installed JREs... button.
- Click the Add button.
(Select Standard VM, where applicable.) - Click the Directory button.
- Browse to your JDK version (not JRE) of your installed Java
(e.g.C:\Program Files\Java\jdk1.7.0_04
). - Click Finish and OK.
- Select the JDK at Separate JRE and click Close.
- Re-run your Ant script — have fun!
This worked in a particular scenario I encountered.
Solution 2:
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.
Solution 3:
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