Unable to locate tools.jar
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
Install the Java SDK.
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_21Close/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.
Related videos on Youtube
olidev
Updated on February 24, 2022Comments
-
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 filetools.jar
is not there.-
Edwin Dalorzo about 13 yearsI think tools belongs to the JDK not to the JRE. Isn´t so? C:\Program Files\Java\jdk1.6.0_24\lib
-
Peter Flynn over 10 yearsAs an aside, what I find astonishing is that the program actually said where it looked. So few programs provide this useful clue.
-
Arashsoft about 8 yearsAlso see the duplicate question: stackoverflow.com/q/9119479/3328979 Answers there are somehow better than here.
-
stopanko about 2 yearsIn 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 about 13 yearsyes, you are right! but how can I uninstall jre? thanks in advance
-
Sean Patrick Floyd about 13 yearsStart > Control Panel > Software (or similar, depending on Win* version)
-
olidev about 13 yearsbut there is no option like that to remove jre. I just checked!
-
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 over 11 yearsthis. thanks! (for those of us who have various jre/jdk versions installed)
-
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 almost 11 yearsAdd JAVA_HOME and the /bin directory to your path. You realize that this answer is two years old, right?
-
John over 10 yearsit worked for me..earlier i gave the path with \bin also..that was the issue
-
Luke over 10 yearsThanks, I wish I could give you 2 ups!
-
krinn over 10 yearsJAVA_HOME variable fixed everything, thanks a lot :)
-
Daniel W. over 10 years
PATH
with/bin
,JAVA_HOME
without/bin
-
kcho0 over 9 yearsThanks, I was loooking for this for hours!!
-
S_M over 9 yearsis this approach recommendable?
-
Xavi Montero about 9 yearsIn ubuntu:
# apt-get install default-jdk
and the error disappears. -
duffymo about 9 yearsThe key? JDK. That's what has the tools. JRE does not.
-
Yigang Wu over 8 yearsI got the same issue with windows, use you way solved my problem.
-
real_paul over 8 yearsPolluting 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 about 8 yearsNot necessarily. It looks to me like they might have
JAVA_HOME
set to thejre
inside of thejdk
instead of to thejdk
itself. -
duffymo about 8 yearsThis answer was given and accepted almost five years ago. You should use your time more wisely than trolling old answers.
-
Umar Abbas about 7 yearsWork like charm on Windows8.1
-
Heidi about 7 yearsWORK LIKE A CHARM!! THANKS
-
Ahmed Ismail about 6 years
apt-get install default-jdk
did the trick, thanks @Xavi Montero -
schlenger almost 6 yearsObviously, you can use 'sudo apt-get install openjdk-8-jdk openjdk-8-jre' for Java 8
-
Mr Smith about 5 yearsi'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 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 about 5 yearsI was missing
JAVA_HOME
in my configuration. I resolved this error by addingJAVA_HOME
to environment variables and%JAVA_HOME%\bin
toPath
. -
Mithun Kumar over 4 yearsi have copied from jdk/lib/tools.jar to jre/lib/ folder , it started working after that.
-
Cummings over 4 yearsI 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 over 3 yearsThis answer is more relevant today than the earlier upvoted answers
-
Roman Golyshev about 3 yearsThanks for this workaround! In my case I copied
corretto-1.8.0_282\lib\tools.jar
tocorretto-1.8.0_282\jre\lib\ext\tools.jar
, and it resolved unstoppable stream ofClassNotFound
exceptions -
Ryan Leach over 2 yearsAdding information on how to migrate maven builds still expecting tools.jar would be great.