Unable to find a javac on Eclipse

After upgrading the java version on my windows laptop I started getting the following error in eclipse while compiling the java project using Ant

Unable to find a javac
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

Java Upgrade was an issue?

My eclipse version is Helios. Old version of Java on my system was jdk1.6_13 and Eclipse was working fine with it. I am using Ant to build the java project within Eclipse.

For the project needs, I had to migrate the system’s java version to jdk1.6_27. I completely uninstalled the old java and reinstalled the new version of java on the system. Having done this I restarted the Eclipse IDE. After running the Ant build from IDE I started getting the above said error.

I updated the JAVA_HOME environment variable on the system to point to the latest. Tried adding required java jars in the CLASSPATH environment variable. Also verified from the commandline that indeed it is picking up the latest installed java.

BTW it is clearly mentioned on the wiki that Eclipse DOES NOT consult the JAVA_HOME environment variable.

So I tried to explicitly update the JRE configuration in Eclipse by adding it from Window->Preferences->Java->Installed JREs but with no success in removing the error.

Finally got it working

At last somebody suggested to explicitly add the tools.jar in the Ant configuration and that resolved the issue.

To do that, go to Window->Preferences->Ant->Runtime in Eclipse IDE. Under Classpath tab there is ‘Global Entries’ where add the entry of tools.jar from the currently installed JDK using ‘Add External JARs’ button.

And that’s it. It solved the issue. Ant build just runs fine as earlier. As a curiosity I checked on one of my old setup of Eclipse on the other machine to see the ‘Global Entries’ in the Ant configuration. And the entry of tools.jar from the currently installed java was already there. So it seems after reinstalling the java, this entry goes away which then needs to be set explicitly.


Posted on September 29, 2011, in tech and tagged . Bookmark the permalink. 2 Comments.

  1. Ajit,
    Thanks for your valuable solution. It helped me to resolve the issue.

    Roopesh 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: