Unable to locate tools.jar

I am building a project in Java.

I have this error:

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar

I have installed a JDK and the folder: C:\Program Files\Java\jre6\lib is in my system but the file tools.jar is not there.


Solution 1:

Yes, you've downloaded and installed the Java Runtime Environment (JRE) instead of the Java Development Kit (JDK). The latter has the tools.jar, java.exe, javac.exe, etc.

Solution 2:

In case this is still an issue for anyone, I have a bit of clarification on the previous answers. I was running into this same issue using ant with only a JDK installed. Although, the JDK installer gave me a directory structure like this:

 Directory of C:\Program Files\Java

05/08/2012  09:43 AM    <DIR>          .
05/08/2012  09:43 AM    <DIR>          ..
05/08/2012  09:46 AM    <DIR>          jdk1.7.0_04
05/08/2012  09:19 AM    <DIR>          jre6
05/08/2012  09:44 AM    <DIR>          jre7
               0 File(s)              0 bytes

and when I ran ant, it complained about not finding tools.jar under the jre7 subdirectory. It wasn't until I set "JAVA_HOME=C:\Program Files\Java\jdk1.7.0_04" that the error went away.

Solution 3:

  1. Install the Java SDK.

  2. Add a System Environment Variable called JAVA_HOME with the value of JDK location.
    Go to Control Panel\System and Security\System. Advanced System Settings, Environment Variables, System Variables, New... Example:
    Variable Name:JAVA_HOME
    Variable Value: C:\Program Files\Java\jdk1.7.0_21

  3. Close/reopen your CMD window so that the new variable takes effect before attempting to re-run the ant command.

Solution 4:

I had the same problem and copying C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar to C:\Program Files\Java\jre6\lib\ext worked for me

Solution 5:

If you have installed JDK 9.0.1 you will also have this problem as the tools.jar has been deprecated. See migration document.