Unable to locate tools.jar

366,853

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.

Share:
366,853

Related videos on Youtube

olidev
Author by

olidev

Updated on February 24, 2022

Comments

  • olidev
    olidev about 2 years

    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.

    • Edwin Dalorzo
      Edwin Dalorzo about 13 years
      I think tools belongs to the JDK not to the JRE. Isn´t so? C:\Program Files\Java\jdk1.6.0_24\lib
    • Peter Flynn
      Peter Flynn over 10 years
      As an aside, what I find astonishing is that the program actually said where it looked. So few programs provide this useful clue.
    • Arashsoft
      Arashsoft about 8 years
      Also see the duplicate question: stackoverflow.com/q/9119479/3328979 Answers there are somehow better than here.
    • stopanko
      stopanko about 2 years
      In my case problem was in a path. I was trying to use script that was in the folder with a space in a name. I was trying to run ./bin/kafka-console-consumer.sh from the binaries kafka folder. when i was asked to build project first with ./gradlew jar -PscalaVersion=2.13.6. This build command actually generated such error for me.
  • olidev
    olidev about 13 years
    yes, you are right! but how can I uninstall jre? thanks in advance
  • Sean Patrick Floyd
    Sean Patrick Floyd about 13 years
    Start > Control Panel > Software (or similar, depending on Win* version)
  • olidev
    olidev about 13 years
    but there is no option like that to remove jre. I just checked!
  • Sean Patrick Floyd
    Sean Patrick Floyd about 13 years
    @Joesy OK, if you can't find it, just leave it, there's no need to deinstall it (except to recover disk space). You can have many JDKs and / or JREs installed in parallel
  • darkAsPitch
    darkAsPitch over 11 years
    this. thanks! (for those of us who have various jre/jdk versions installed)
  • Mercenary
    Mercenary almost 11 years
    @olidev checking this now but still can't stop pointing out the issue!! How can this be your answer? You have already mentioned that you have installed jdk and jre. I'm actually facing a similar problem and it still continues :-( . Need to know how you got it working??
  • duffymo
    duffymo almost 11 years
    Add JAVA_HOME and the /bin directory to your path. You realize that this answer is two years old, right?
  • John
    John over 10 years
    it worked for me..earlier i gave the path with \bin also..that was the issue
  • Luke
    Luke over 10 years
    Thanks, I wish I could give you 2 ups!
  • krinn
    krinn over 10 years
    JAVA_HOME variable fixed everything, thanks a lot :)
  • Daniel W.
    Daniel W. over 10 years
    PATH with /bin, JAVA_HOME without /bin
  • kcho0
    kcho0 over 9 years
    Thanks, I was loooking for this for hours!!
  • S_M
    S_M over 9 years
    is this approach recommendable?
  • Xavi Montero
    Xavi Montero about 9 years
    In ubuntu: # apt-get install default-jdk and the error disappears.
  • duffymo
    duffymo about 9 years
    The key? JDK. That's what has the tools. JRE does not.
  • Yigang Wu
    Yigang Wu over 8 years
    I got the same issue with windows, use you way solved my problem.
  • real_paul
    real_paul over 8 years
    Polluting local installations with classes which clearly don't belong there can lead to the Works on my machine syndrome. That is even if a formal build process is in place. tools.jar, which contains non-core classes for support of the tools and utilities in the JDK
  • ArtOfWarfare
    ArtOfWarfare about 8 years
    Not necessarily. It looks to me like they might have JAVA_HOME set to the jre inside of the jdk instead of to the jdk itself.
  • duffymo
    duffymo about 8 years
    This answer was given and accepted almost five years ago. You should use your time more wisely than trolling old answers.
  • Umar Abbas
    Umar Abbas about 7 years
    Work like charm on Windows8.1
  • Heidi
    Heidi about 7 years
    WORK LIKE A CHARM!! THANKS
  • Ahmed Ismail
    Ahmed Ismail about 6 years
    apt-get install default-jdk did the trick, thanks @Xavi Montero
  • schlenger
    schlenger almost 6 years
    Obviously, you can use 'sudo apt-get install openjdk-8-jdk openjdk-8-jre' for Java 8
  • Mr Smith
    Mr Smith about 5 years
    i've tried all this & still get the issue with tools.jar. Is Randoop worth the effort? Meaning does it generate decent unit tests? The frustrating part of this is that EVERY other java program on my Windows box works fine.
  • Ivaylo Slavov
    Ivaylo Slavov about 5 years
    @MrSmith , What is the path that Randoop looks for when you receive the error. Maybe Randoop has its own env setting that tells it where the JRE is? Also, did you reopen your shell windows (if running from shell) after changing your env variables?
  • bobasti
    bobasti about 5 years
    I was missing JAVA_HOME in my configuration. I resolved this error by adding JAVA_HOME to environment variables and %JAVA_HOME%\bin to Path.
  • Mithun Kumar
    Mithun Kumar over 4 years
    i have copied from jdk/lib/tools.jar to jre/lib/ folder , it started working after that.
  • Cummings
    Cummings over 4 years
    I had to force this. Ant 10+ is looking for the JDK in an unknown variable. I could not find where it was getting the JDK, but when I can in command line and forced JAVA HOME it worked.
  • deepak
    deepak over 3 years
    This answer is more relevant today than the earlier upvoted answers
  • Roman Golyshev
    Roman Golyshev about 3 years
    Thanks for this workaround! In my case I copied corretto-1.8.0_282\lib\tools.jar to corretto-1.8.0_282\jre\lib\ext\tools.jar, and it resolved unstoppable stream of ClassNotFound exceptions
  • Ryan Leach
    Ryan Leach over 2 years
    Adding information on how to migrate maven builds still expecting tools.jar would be great.