Ant Errors: “Perhaps JAVA_HOME does not point to the JDK”

In this case, I was working on a Linux environment (RHEL Server 6.2) which had previously been using the OpenJDK version of Java. For dev purposes, I was required to remove OpenJDK and install an IBM JDK instead. After this, any attempt to build through Ant gave the following error…

BUILD FAILED
{name of file}: 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 "/opt/ibm/java-i386-60/jre"

At this point I had already set JAVA_HOME on the computer to “/opt/ibm/java-i386-60/bin” and had also created a similar Classpath Variable in Eclipse.

However, there was one thing I had missed. After removing OpenJDK, a reference to it was still in place in the Eclipse preferences. To solve this error I did the following:

Edit Ant’s runtime properties via Window > Preferences > Ant > Runtime. Next, under the Classpath tab, expand the Global Entries entry.
Here, Ant requires a reference to the tools.jar file from your desired JDK. In my case, an old reference still existed belonging to OpenJDK – which I deleted.
Finally, click Add External Jars and select tools.jar from your desired JDK directory (e.g., /opt/ibm/java-i386-60/lib/tools.jar). Your build should now compile successfully.

Note: This error can also occur when no reference to tools.jar exists at all. The steps above will also work in this situation – just exclude the part about removing the OpenJDK file.

This entry was posted in Code Monkey and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*