Unable to locate tools.jar
Asked Answered
V

36

198

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.

Voodoo answered 20/4, 2011 at 13:7 Comment(4)
I think tools belongs to the JDK not to the JRE. Isn´t so? C:\Program Files\Java\jdk1.6.0_24\libCarpenter
As an aside, what I find astonishing is that the program actually said where it looked. So few programs provide this useful clue.Ingraft
Also see the duplicate question: https://mcmap.net/q/129859/-quot-unable-to-locate-tools-jar-quot-when-running-ant-duplicate/3328979 Answers there are somehow better than here.Unchurch
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.Jeanettajeanette
C
204

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.

Choking answered 20/4, 2011 at 13:10 Comment(9)
@Voodoo 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??Slotter
Add JAVA_HOME and the /bin directory to your path. You realize that this answer is two years old, right?Choking
In ubuntu: # apt-get install default-jdk and the error disappears.Ballyhoo
The key? JDK. That's what has the tools. JRE does not.Choking
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.Boost
This answer was given and accepted almost five years ago. You should use your time more wisely than trolling old answers.Choking
apt-get install default-jdk did the trick, thanks @Xavi MonteroCreighton
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.Lanoralanose
i have copied from jdk/lib/tools.jar to jre/lib/ folder , it started working after that.Appleby
C
91

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.

Coggins answered 9/5, 2012 at 16:0 Comment(2)
this. thanks! (for those of us who have various jre/jdk versions installed)Suppressive
it worked for me..earlier i gave the path with \bin also..that was the issueObduce
C
42
  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.

Cabot answered 21/5, 2013 at 17:57 Comment(2)
JAVA_HOME variable fixed everything, thanks a lot :)Stefanstefanac
PATH with /bin, JAVA_HOME without /binGlede
U
31

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

Underwood answered 18/3, 2013 at 7:21 Comment(2)
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 JDKNemhauser
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 exceptionsAirflow
C
23

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

Clapp answered 27/12, 2017 at 20:3 Comment(2)
This answer is more relevant today than the earlier upvoted answersProverbial
Adding information on how to migrate maven builds still expecting tools.jar would be great.Unrealizable
G
10

Set your JAVA_HOME environmental variable to point to C:\Program Files\Java\jdk1.7.0_02.

Gdynia answered 25/1, 2013 at 1:33 Comment(0)
A
10

If you are in Linux you can solve this by installing java on the system:

sudo apt-get install openjdk-7-jdk openjdk-7-jre
Aldous answered 30/9, 2014 at 22:52 Comment(1)
Obviously, you can use 'sudo apt-get install openjdk-8-jdk openjdk-8-jre' for Java 8Meristic
M
7

No, according to your directory structure, you have installed a JRE, not a JDK. There's a difference.

C:\Program Files\Java\jre6\lib
                      ^^^^

It should be something like:

C:\Program Files\Java\jdk1.6.0_24
Marmalade answered 20/4, 2011 at 13:9 Comment(4)
yes, you are right! but how can I uninstall jre? thanks in advanceVoodoo
Start > Control Panel > Software (or similar, depending on Win* version)Marmalade
but there is no option like that to remove jre. I just checked!Voodoo
@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 parallelMarmalade
M
5

Don't spend too much time looking for tools.jar. If you get an error like that, don't be upset.

If you already have java JDK 1.5, go to your lib folder, and the tools.jar should be available there. Copy and paste it in your ant bin folder, then try to use the command ant -version.

You should see the expected result.

Merat answered 29/9, 2012 at 10:22 Comment(1)
is this approach recommendable?Neff
H
5

I had the same issue on a linux machine. I was quite frustrated at first, because I have installed both the JDK and JRE. I am using version 1.6, 1.7 and 1.8 simultaneously, and I have played a lot with the alternatives to have everything set properly.

The problem was quite stupid to solve, yet counter-intuitive. While I was using the correct JDK, I paid attention to the path of the tools jar maven complained about - it was expecting it to be

$JAVA_HOME\..\lib\tools.jar

The $JAVA_HOME variable pointed directly to my jdk folder (/usr/local/java which was also the correct $PATH entry and alternative sym link). It actually searches for the lib folder outside the java directory, because:

$JAVA_HOME\..\lib\tools.jar

will resolve to

/usr/local/lib/tools.jar

and that is not a valid location.

To solve this, the $JAVA_HOME variable should instead point to this location /usr/local/java/jre (assuming the JDK path is /usr/local/java) -- there is actually jre folder inside the JDK installation directory, that comes with each JDK. This new setup will cause maven to look at the JRE directory, that is part of the JDK:

$JAVA_HOME\..\lib\tools

which now resolves to

/usr/local/java/jre/../lib/tools.jar

and finally to

/usr/local/java/lib/tools.jar

which is where the tools.jar really resides.

So, even if you are indeed using the JDK instead of the JRE, the $JAVA_HOME has to point to the JRE. Remember, the OS alternative should still refer to the JDK.

Hun answered 24/6, 2015 at 11:44 Comment(3)
I got the same issue with windows, use you way solved my problem.Botsford
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.Evaporite
@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?Hun
C
3

go to your jdk path where you installed your java

For e.g In my PC JDK installed in the following path

"C:\Program Files\Java\jdk1.7.0_17\";

After go to the lib folder e.g "C:\Program Files\Java\jdk1.7.0_17\lib"

in the lib directory there is tool.jar file

Copy this file and past it in the lib forlder of jre7 directory for e.g

"C:\Program Files\Java\jre7\lib"

Clover answered 3/4, 2013 at 5:53 Comment(0)
R
3

You may face similar problem on Ubuntu:

Embedded error: tools.jar not found: /usr/lib/jvm/java-7-openjdk-amd64/jre/../lib/tools.jar

The problem is with JAVA_HOME that is not set properly.

So, on Ubuntu 14.04 x64 using Java8:

sudo apt-get install openjdk-8-jdk openjdk-8-jre
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
Rhettrhetta answered 26/6, 2016 at 20:24 Comment(0)
N
3

As many people mentioned, it looks like you are looking in your JRE instead of the JDK for the tools.jar file.

I would also like to mention that on recent versions of the JDK, there is no more tools.jar file. I downloaded the most recent JDK as of today (JDK version 12) and I could not find any tools.jar. I had to download JDK version 8 (1.8.0) here https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html to get the tools.jar file. I downloaded that version, took the tools.jar file and put it into my recent version's lib folder.

Newburg answered 2/4, 2019 at 20:51 Comment(0)
M
3

It's worth observing that tools.jar has been removed from the JDK since Java 9. https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-055EA9F4-835E-463F-B9E1-9081B3D9E55D

If people are facing this issue compiling a Java program with JDK 9+, you may need to review the dependencies of your projects.

In my case, I was trying to compile a project using AspectJ and the Maven plugin org.codehaus.mojo:aspectj-maven-plugin:1.11. After searching online, I found an alternative that supports Java 9+: dev.aspectj:aspectj-maven-plugin:1.13.M3.

Marquez answered 9/7, 2021 at 19:52 Comment(0)
S
2

I had the same problem even after installing Java JDK and set JAVA_HOME to ..\jdk1.6.0_45\bin folder.

Ant is still trying to find tools.jar in C:\Program Files\Java\jre6\lib folder.
I've fixed it by adding JAVACMD environment variable and set path for it to java.exe in the jdk folder.
In my case it was C:\Program Files\Java\jdk1.6.0_45\bin\java.exe

Ss answered 28/1, 2014 at 5:20 Comment(0)
F
2

it has been solved with me in windows os by setting the JAVA_HOME variable before running as follows:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111

Fisken answered 17/5, 2017 at 11:16 Comment(1)
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.Shul
C
1

Make sure that both the %JAVA_HOME% and %JAVA_HOME%/bin paths are added to your PATH variable.

All the answers about copying tools.jar into the correct position is a poor idea at best.

Make sure that your IDE can find these jars the way it was designed and intended for.

Cipolin answered 6/10, 2013 at 22:9 Comment(0)
C
1

In eclipse window> preferences>Java> Installed JRE, I pointed the directory to the jre directory in the jdk 1.7 and i worked file for me e.g C:\Program Files\Java\jdk1.7.0_71\jre

Circumstantial answered 2/5, 2015 at 18:9 Comment(0)
U
1

I had my JDK_path (C:\Program Files\Java\jdk1.7.0_79) in my JAVA_HOME and also the JDK_path\bin in my PATH. But, still my ant was using the JRE instead of JDK.

The issue was I had C:\ProgramData\Oracle\Java\javapathbefore my JDK_path in PATH variable. I simply moved my JDK_path before the oracle one and the issue solved.

Unchurch answered 27/4, 2016 at 20:11 Comment(0)
H
1

solving this problem I have simply copied the tools.jar file from C:\Program Files\Java\jre1.8.0_112\lib to C:\Program Files\Java\jdk1.8.0_112\lib so that I have two tools.jar files instead of one and problem disappeared.

Hathaway answered 1/2, 2017 at 9:53 Comment(0)
A
0
Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar

if you have installed jdk then

..Java/jdkx.x.x

folder must exist there so in stall it and give full path like

C:\Program Files\Java\jdk1.6.0\lib\tools.jar
Aronson answered 20/4, 2011 at 13:14 Comment(0)
C
0

Make sure that your classpath is set correctly and pointing to the correct version of the JDK that you have installed. Also, are you using Open JDK? I have had this issue before after I tried to move from open JDK to Suns JDK. This is an example of how that issue could be fixed.

Cabbagehead answered 20/4, 2011 at 13:14 Comment(0)
D
0

maven-compiler-plugin use jdk ,not jre, tools.jar is in C:\Program Files\Java\jdk1.6.0\lib\tools.jar you must config project JRE System Libary with jdk,not jar. This is the simplest solution.

Dubai answered 28/12, 2013 at 7:29 Comment(0)
G
0
  • Right click on your ant file
  • Go to "Run as" then click on "Ant Build..."
  • Go to the "JRE" tab
  • Select a JDK and not a JRE
Gondar answered 30/9, 2016 at 10:3 Comment(0)
M
0

For me what's working: I downloaded an old version of Java 1.7

I actually set my JAVA_HOME from C:/program files X86/Java BUT after I installed the 1.7 version I had another Java in program files/Java. And at this moment I found the tools.jar here. Then I changed for this new path and it's working

Mizell answered 28/5, 2017 at 19:13 Comment(0)
C
0

I was also facing the same error. This was removed after setting Java_Home path to C:\Program Files\Java\jdk1.8.0_121. Please ensure bin is not included in the path and no slash is there after jdk1.8.0_121 after you have defined %JAVA_HOME%\bin in the system path variable.

Credenza answered 7/9, 2017 at 12:40 Comment(0)
S
0

If you're in a RHEL environment the package name containing tools.jar would end with "openjdk-devel".

Scupper answered 24/7, 2018 at 15:1 Comment(0)
A
0

This is the solution for Windows: in Computer > Advanced system settings > Advanced > Environment variables..., add this in System variables:

enter image description here

Artina answered 5/8, 2018 at 12:52 Comment(0)
B
0

I have downloaded tools.jar and after that I copied it into path in error message.

C:\Program Files\Java\jdk-11.0.1\bin > paste here tools.jar

After that I have restarted Spring Tool Suit 4 and everything was working. When I was trying to fix that problem I have made new environmental variable: Control Panel / System / Advenced / Environmental variables / new Name : JAVA_HOME Value: C:\Program Files\Java\jdk-11.0.1 But I do not know is it necessary.

Bracteole answered 4/12, 2018 at 7:39 Comment(0)
P
0

maybe you have updated the JREs in the OS, and the addition has added in the "path" of the environment variables an entry ".../Oracle/jer" that overwrites your JAVA_HOME. try to remove it from the "path" by leaving JAVA_HOME.

Payment answered 31/1, 2019 at 15:14 Comment(0)
O
0

Incase it helps, the problem for me was that I had 2 entries in my PATH environment variable which pointed to a location containing the javaw executable.

I cleaned up the variable to make sure that "%JAVA_HOME%\bin" was the only entry referencing a location containing my java executables.

Opal answered 12/12, 2019 at 11:41 Comment(0)
B
0

This happens when the Environment Variable JAVA_HOME is not set, or points to the wrong directory. You can see the value that Ant has by running the command:

ant -diagnostics

And looking for the line that shows java.home. If you have grep installed then you can simple run:

ant -diagnostics | grep java.home

To fix the issue, set the JAVA_HOME Environment Variable to the JDK directory. While setting the variable differs slightly between *nix and Windows, the rest works the same on all operating systems. So it doesn't matter if you use the GUI that Windows provides, or the set or setx commands, as long as the value is set prior to calling ant (if you've set it globally then it must exist before you open the shell/terminal window).

After setting JAVA_HOME you can run ant -version, for example, and get the result, e.g.

Apache Ant(TM) version 1.10.8 compiled on May 10 2020

Besse answered 16/8, 2020 at 15:45 Comment(0)
E
0

Step1 Check your jdk is installed. and variable path is setted. Step2 unistall your eclipes and reinstall it. other wise It will continue to be a problem

Eugene answered 25/10, 2020 at 11:58 Comment(0)
M
0

The latest versions of Java do not have tools.jar in the lib folder. Remove tools.jar entry in environment variables and retry it.

Montage answered 3/12, 2022 at 23:43 Comment(0)
N
0

I am using java openjdk 12 with Eclipse IDE (Version: 2022-06 (4.24.0) Build id: 20220609-1112) and I placed the tools.jar under the lib folder (C:\Program Files\OpenJDK\jdk-12.0.2\lib) and pom.xml file had it as a dependency for sun tools:

<!-- https://mvnrepository.com/artifact/com.sun/tools -->
    <dependency>
       <groupId>com.sun</groupId>
       <artifactId>tools</artifactId>
       <version>1.5.0</version>
       <scope>system</scope>
       <systemPath>C:\Program Files\OpenJDK\jdk-12.0.2\lib\tools.jar</systemPath>
    </dependency>

This works in jdk 8 and 12, but I will recreate the project without this dependency in my next release version since this maven project was created back in 2018.

Notification answered 27/6, 2023 at 16:34 Comment(0)
A
-1

I have resolved tool.jar file error recently. I am using eclipse oxygen ide. It works perfectly and easy. Repeat these steps on your system as

  1. Download tool.jar file according to your jre jdk version. Lets suppose tool.jar file is 1.8.0.tool.jar

  2. After donwload 1.8 .0 tool.jar file rename is as as tool.jar

  3. Then go to your jdk installation folder

  4. Then go to lib folder open it

  5. And paste here

  6. You will make this type path. E:\jdk 8\lib\tools.jar

Aho answered 5/12, 2019 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.