How to Get Ant Compiling in Eclipse

10:10 PM Sep 22nd 2006 from web under ,

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.

Reader Comments

Show all comments
  1. wattle9 says:

    Thanks a heap for sharing a your knowledge with us.Really helpful article.

  2. Perry says:

    Thanks!!! You and Google saved me countless hours I’m sure…

  3. ok says:

    good site jedcrm

  4. Pechersk says:

    Hi,

    It worked for me too. Thanks for sharing knowledge. :)

  5. PatoKike says:

    Hi
    thank you on this tip, I have read a lot of sites and most of them just advice the first point. The second one fix my issue :)

    So thank you!!

  6. Paul Grimwood says:

    I had this very annoying problem and unhelpful error message when i updated to Java 6 update 2. As per your suggestion: ‘Preferences > Ant > Runtime. Choose the Classpath tab. Select the Global Properties node in the tree and click Add External JARs’, I selected tools.jar from the new JDK directory – things worked.

Leave a Reply