Ant "JAVA_HOME does not point to the JDK" - but it does

I was having the same message when running ANT through Eclipse.

What worked for me:

  1. In Eclipse, access the menu: "Window -> Preferences";
  2. Access "Ant -> Runtime", at the tree;
  3. Access the Classpath tab;
  4. Expand the "Global Entries" item;
  5. Inside Global Entries, the path to tools.jar was wrong. It was pointing to an older version of Java;
  6. I removed the wrong entry and added the correct one with "Add External Jars" button. It worked.

enter image description here


The solution "Had to copy C:\Program Files\Java\jdk1.6.0_10\lib\tools.jar to C:\Program Files\Java\jre6\lib\ext" from here was great helpful and worked for me.


The real message is that Ant can't find com.sun.tools.javac.Main.

Which, together with the fact that the latest "Sun" (Oracle) JDK is 1.7.0_13 (or maybe _14, but definitely not the "_52" that your install dir indicates), makes me think that you're not using a distribution that Ant recognizes. You can verify this by running jar tvf $JAVA_HOME/lib/tools.jar, and looking for that class.

The Ant Manual talks about ways to work with different compilers. Since I've only used "Sun" compilers, I'm afraid that I can't give you any pointers.


Edit: you could also try setting fork="yes" in your build file. This should run the compiler executable rather than trying to invoke the compiler class.

Tags:

Java

Eclipse

Ant