无法找到tools.jar
我正在用 Java 构建一个项目。
我有这个错误:
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
我已经安装了 JDK,并且文件夹:C:\Program Files\Java\jre6\lib
在我的系统中,但文件 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
是的,您已经下载并安装了 Java 运行时环境 (JRE),而不是 Java 开发工具包 (JDK)。后者有tools.jar、java.exe、javac.exe等。
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.
如果这对任何人来说仍然是一个问题,我对之前的答案进行一些澄清。我在使用仅安装了 JDK 的 ant 时遇到了同样的问题。虽然,JDK安装程序给了我这样的目录结构:
当我运行ant时,它抱怨在jre7子目录下找不到tools.jar。直到我
设置“JAVA_HOME=C:\Program Files\Java\jdk1.7.0_04”
错误才消失。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:
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.安装Java SDK。
添加名为 JAVA_HOME 的系统环境变量,其值为 JDK 位置。
转至控制面板\系统和安全\系统。高级系统设置、环境变量、系统变量、新建...示例:
变量名称:JAVA_HOME
变量值:C:\Program Files\Java\jdk1.7.0_21
关闭/重新打开 CMD 窗口,以便新变量在尝试重新运行 ant 命令之前生效。
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_21
Close/reopen your CMD window so that the new variable takes effect before attempting to re-run the ant command.
我遇到了同样的问题,复制
C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar
到C:\Program Files\Java\jre6\lib\ext
为我工作I had the same problem and copying
C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar
toC:\Program Files\Java\jre6\lib\ext
worked for me如果您安装了 JDK 9.0.1,您也会遇到此问题,因为 tools.jar 已被弃用。请参阅迁移文档。
If you have installed JDK 9.0.1 you will also have this problem as the tools.jar has been deprecated. See migration document.
将
JAVA_HOME
环境变量设置为指向C:\Program Files\Java\jdk1.7.0_02
。Set your
JAVA_HOME
environmental variable to point toC:\Program Files\Java\jdk1.7.0_02
.如果您使用的是 Linux,您可以通过在系统上安装 java 来解决此问题:
If you are in Linux you can solve this by installing java on the system:
不,根据你的目录结构,你安装的是JRE,而不是JDK。有区别。
它应该是这样的:
No, according to your directory structure, you have installed a JRE, not a JDK. There's a difference.
It should be something like:
不要花费太多时间寻找
tools.jar
。如果您遇到这样的错误,请不要沮丧。如果您已经有 java JDK 1.5,请转到您的
lib
文件夹,并且tools.jar
应该在那里可用。将其复制并粘贴到 antbin
文件夹中,然后尝试使用命令ant -version
。您应该看到预期的结果。
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 thetools.jar
should be available there. Copy and paste it in your antbin
folder, then try to use the commandant -version
.You should see the expected result.
我在 Linux 机器上遇到了同样的问题。一开始我很沮丧,因为我已经安装了JDK和JRE。我同时使用 1.6、1.7 和 1.8 版本,并且我尝试了很多替代方案以确保一切设置正确。
这个问题解决起来非常愚蠢,但却违反直觉。当我使用正确的 JDK 时,我注意到 maven 抱怨的工具 jar 的路径 - 它期望它是
$JAVA_HOME
变量直接指向我的jdk
文件夹(/usr/local/java
这也是正确的$PATH
条目和替代符号链接)。它实际上搜索 java 目录外部的lib
文件夹,因为:将解析为
并且这不是一个有效的位置。
为了解决这个问题,
$JAVA_HOME
变量应该指向这个位置/usr/local/java/jre
(假设JDK路径是/usr/local/ java
)——JDK安装目录中实际上有一个jre
文件夹,每个JDK都带有该文件夹。这个新设置将导致 maven 查看 JRE 目录,它是 JDK 的一部分:现在解析为
并最终解析为
tools.jar
真正所在的位置。因此,即使您确实使用 JDK 而不是 JRE,$JAVA_HOME 也必须指向 JRE。请记住,操作系统替代方案仍应引用 JDK。
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
The
$JAVA_HOME
variable pointed directly to myjdk
folder (/usr/local/java
which was also the correct$PATH
entry and alternative sym link). It actually searches for thelib
folder outside the java directory, because:will resolve to
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 actuallyjre
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:which now resolves to
and finally to
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.
转到安装 java 的 jdk 路径
例如,在我的 PC 中,JDK 安装在以下路径
“C:\Program Files\Java\jdk1.7.0_17\”;
转到lib文件夹后,例如
lib目录中的“C:\Program Files\Java\jdk1.7.0_17\lib”,其中有tool.jar文件
复制此文件并将其粘贴到jre7目录的lib文件夹中
例如
“C:\Program Files\Java\jre7\lib”
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"
您可能会在 Ubuntu 上遇到类似的问题:
问题是 JAVA_HOME 设置不正确。
因此,在使用 Java8 的 Ubuntu 14.04 x64 上:
You may face similar problem on Ubuntu:
The problem is with JAVA_HOME that is not set properly.
So, on Ubuntu 14.04 x64 using Java8:
正如许多人提到的,您似乎正在 JRE 而不是 JDK 中查找 tools.jar 文件。
我还想提一下,在最新版本的 JDK 上,不再有 tools.jar 文件。我今天下载了最新的 JDK(JDK 版本 12),但找不到任何 tools.jar。我必须在这里下载 JDK 版本 8 (1.8.0) https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 获取tools.jar 文件。我下载了该版本,获取了tools.jar 文件并将其放入我最新版本的lib 文件夹中。
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.
值得注意的是,自 Java 9 以来,tools.jar 已从 JDK 中删除。 https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-055EA9F4-835E-463F-B9E1-9081B3D9E55D
如果人们在使用 JDK 9+ 编译 Java 程序时遇到此问题,您可能需要检查项目的依赖关系。
就我而言,我尝试使用 AspectJ 和 Maven 插件
org.codehaus.mojo:aspectj-maven-plugin:1.11
编译一个项目。在网上搜索后,我找到了一个支持Java 9+的替代方案:dev.aspectj:aspectj-maven-plugin:1.13.M3
。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
.即使安装了 Java JDK 并将
JAVA_HOME
设置为..\jdk1.6.0_45\bin
文件夹后,我也遇到了同样的问题。Ant 仍在尝试在
C:\Program Files\Java\jre6\lib
文件夹中查找tools.jar
。我已通过添加
JAVACMD
环境变量并将其路径设置为jdk
文件夹中的java.exe
来修复此问题。就我而言,它是
C:\Program Files\Java\jdk1.6.0_45\bin\java.exe
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
inC:\Program Files\Java\jre6\lib
folder.I've fixed it by adding
JAVACMD
environment variable and set path for it tojava.exe
in thejdk
folder.In my case it was
C:\Program Files\Java\jdk1.6.0_45\bin\java.exe
我在 Windows 操作系统中通过在运行之前设置 JAVA_HOME 变量解决了这个问题,如下所示:
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111
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
确保 %JAVA_HOME% 和 %JAVA_HOME%/bin 路径都添加到 PATH 变量中。
所有关于将tools.jar复制到正确位置的答案充其量都是一个糟糕的主意。
确保您的 IDE 可以按照其设计和预期方式找到这些 jar。
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.
在 Eclipse 窗口中>首选项>Java>安装了JRE,我将目录指向jdk 1.7中的jre目录,并为我工作了文件
例如 C:\Program Files\Java\jdk1.7.0_71\jre
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
我的
JAVA_HOME
中有我的 JDK_path (C:\Program Files\Java\jdk1.7.0_79
),并且PATH
中有 JDK_path\bin >。但是,我的蚂蚁仍然使用 JRE 而不是 JDK。问题是我在
PATH
变量中的 JDK_path 之前有C:\ProgramData\Oracle\Java\javapath
。我只是将 JDK_path 移到 oracle 路径之前,问题就解决了。I had my JDK_path (
C:\Program Files\Java\jdk1.7.0_79
) in myJAVA_HOME
and also the JDK_path\bin in myPATH
. But, still my ant was using the JRE instead of JDK.The issue was I had
C:\ProgramData\Oracle\Java\javapath
before my JDK_path inPATH
variable. I simply moved my JDK_path before the oracle one and the issue solved.解决这个问题我只是将tools.jar文件从C:\Program Files\Java\jre1.8.0_112\lib复制到C:\Program Files\Java\jdk1.8.0_112\lib,这样我就有两个tools.jar文件而不是一个,问题就消失了。
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.
如果你已经安装了jdk,那么
..Java/jdkx.xx
文件夹必须存在,所以安装它并给出完整路径,例如
if you have installed jdk then
..Java/jdkx.x.x
folder must exist there so in stall it and give full path like
确保您的类路径设置正确并指向已安装的 JDK 的正确版本。另外,你使用的是 Open JDK 吗?在我尝试从开放 JDK 迁移到 Suns JDK 后,我曾经遇到过这个问题。 这个是如何解决该问题的示例。
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.
maven-compiler-plugin 使用 jdk,而不是 jre,
tools.jar 位于 C:\Program Files\Java\jdk1.6.0\lib\tools.jar
您必须使用 jdk 配置项目 JRE System Libary,而不是 jar。这是最简单的解决方案。
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.
对我来说有效的是:我下载了旧版本的Java 1.7,
实际上我从C:/program files X86/Java设置了我的JAVA_HOME,但是在安装1.7版本后,我在program files/Java中有另一个Java。这时我在这里找到了tools.jar。然后我改变了这条新路径并且它正在工作
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
我也面临着同样的错误。
将 Java_Home 路径设置为 C:\Program Files\Java\jdk1.8.0_121 后将其删除。
在系统路径变量中定义%JAVA_HOME%\bin后,请确保路径中不包含bin,并且jdk1.8.0_121后面没有斜杠。
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.
如果您处于 RHEL 环境中,包含 tools.jar 的包名称将以“openjdk-devel”结尾。
If you're in a RHEL environment the package name containing tools.jar would end with "openjdk-devel".
这是 Windows 的解决方案:在 Computer > 中高级系统设置>>高级>环境变量...,在系统变量中添加:
< img src="https://i.sstatic.net/7bSlD.jpg" alt="在此处输入图像描述">
This is the solution for Windows: in Computer > Advanced system settings > Advanced > Environment variables..., add this in System variables:
我已经下载了tools.jar,然后将其复制到错误消息中的路径中。
C:\Program Files\Java\jdk-11.0.1\bin >粘贴在这里 tools.jar
之后我重新启动了 Spring Tool Suit 4 并且一切正常。
当我试图解决这个问题时,我创建了新的环境变量:
控制面板/系统/高级/环境变量/新建
名称:JAVA_HOME
值:C:\Program Files\Java\jdk-11.0.1
但我不知道是否有必要。
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.
也许您已经更新了操作系统中的 JRE,并且在环境变量的“路径”中添加了一个条目“.../Oracle/jer”,该条目会覆盖您的 JAVA_HOME。
尝试通过离开 JAVA_HOME 将其从“路径”中删除。
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.