I recently came across a rather confusing issue with Ant not compiling in Eclipse, giving the following error:
[javac] BUILD FAILED: [build file location]
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
I first made sure my Classpath was pointing to my jdk bin, which it was, then I made sure my java compiler (javac) was in the correct directory, which also was in right place.
Now I know Eclipse knows my jre and jdk installs, because it detects it on startup. The only issue that is left is whether or not Eclipse preferences are pointing Ant to the right .jar.
The solution I found, that has worked for me so far, is as follows:
- Go to Window > Preferences > Ant > Runtime. Choose the Classpath tab. Select the Global Properties node in the tree and click Add External JARs. Select tools.jar from your JDK directory.
- Go to Window > Preferences > Java > Installed JREs. Double click your JRE and deselect “Use default system libraries”. Click Add External JARs and add the location of tools.jar to that classpath. Make sure you are using the SDK and not the JRE.
Hope this helps.








