缺少工件 com.sun:tools:jar
我一直在关注入门教程,但在使用 Maven 导入 playn 项目后陷入困境。我正在使用在 64 位 Windows 7 上运行的 Eclipse Indigo。
所有导入的项目都有相同的错误:
Missing Artifact com.sun:tools:jar in all the pom.xml files.
在搜索论坛几个小时后,我尝试过:
安装最新的 Java 1.6.029 更改我的 JAVA_HOME
环境变量以指向 \program files\Java\jdk1.6_029
更改我的 Eclipse Java 首选项以使用 JRE jdk1.6_029
。
我真的很想尝试 playn,但为什么有一些帖子我似乎无法找到解决方案的共识答案。有些人说 Sun 从 64 位 jdk 中删除了某些内容,其他人说您必须编辑 xml 文件,许多人说您已经更改了 JAVA_HOME
,还有人说您必须更改 Eclipse 的 VM 选项。
任何有关清除此问题的帮助将不胜感激,并且可能对许多人有用,因为我在这里没有特别奇怪的设置。
(编辑) 这是第一个项目中的 pom.xml。 Eclipse 标记行中的错误,其中显示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-project</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>playn-android</artifactId>
<name>PlayN Android</name>
<packaging>jar</packaging>
<repositories>
</repositories>
<dependencies>
<dependency>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- needed because Android uses the same JSON code as playn-java;
that should be factored into a library shared by both backends -->
<dependency>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${android.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
</build>
</project>
I've been following the getting started tutorial, but am stuck after I imported the playn project using Maven. I am using Eclipse Indigo running on 64bit Windows 7.
All the imported projects have the same error:
Missing Artifact com.sun:tools:jar in all the pom.xml files.
After a couple hours of searching forums I have tried:
Installing the latest Java 1.6.029
Changing my JAVA_HOME
environment variable to point to \program files\Java\jdk1.6_029
Changing my Eclipse Java preferences to use the JRE jdk1.6_029
.
I would really like to experiment with playn, but why there are a few posts I can't seem to find a consenus answer on the solution. Some people say Sun removed something from the 64bit jdk, others say you must edit your xml files, many people have said you have change your JAVA_HOME
, and another said you have to change your VM options for Eclipse.
Any help on clearing this up would be appreciated, and possibly useful for many, since I do not have a particularly odd setup here.
(edit)
Here is the pom.xml in the first project. Eclipse flags error in the line which says:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-project</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>playn-android</artifactId>
<name>PlayN Android</name>
<packaging>jar</packaging>
<repositories>
</repositories>
<dependencies>
<dependency>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- needed because Android uses the same JSON code as playn-java;
that should be factored into a library shared by both backends -->
<dependency>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${android.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
</build>
</project>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(27)
我刚刚在这个问题上发布了关于同一问题以及我如何解决了它,但我也会将其粘贴(并扩展)在这里,因为它看起来更相关。
在 Windows 7 中使用 Eclipse 时,我遇到了同样的问题,即使我从 Eclipse 设置中的 JRE 列表中删除了 JRE,而只保留了 JDK。
我最终要做的(正如您在问题中提到的)是修改我用来启动 Eclipse 的快捷方式的命令行,以添加 -vm 参数,如下所示:
当然,您可以将其调整为指向 JDK 安装的 bin 目录。这样做的目的是使 Eclipse 本身使用 JDK 而不是 JRE 运行,然后它能够正确找到
tools.jar
。我相信这与 Eclipse 在未指定 JRE 时如何找到其默认 JRE 有关。我猜它倾向于选择 JRE 而不是 JDK(为什么,我不知道)并选择它找到的第一个兼容的 JRE。如果它像 Vladiat0r 的答案所建议的那样离开 Windows 注册表项,它会首先查找 HKLM\Software\JavaSoft\Java Runtime Environment 键,而不是 HKLM\Software\JavaSoft\Java Development套件密钥。
I just posted over on this question about this same issue and how I resolved it, but I'll paste (and expand on) it here as well, since it seems more relevant.
I had the same issue when using Eclipse in Windows 7, even when I removed the JRE from the list of JREs in the Eclipse settings and just had the JDK there.
What I ended up having to do (as you mentioned in your question) was modify the command-line for the shortcut I use to launch Eclipse to add the -vm argument to it like so:
Of course, you would adjust that to point to the bin directory of your JDK install. What this does is cause Eclipse itself to be running using the JDK instead of JRE, and then it's able to find the
tools.jar
properly.I believe this has to do with how Eclipse finds its default JRE when none is specified. I'm guessing it tends to prefer JRE over JDK (why, I don't know) and goes for the first compatible JRE it finds. And if it's going off of Windows registry keys like Vladiat0r's answer suggests, it looks for the
HKLM\Software\JavaSoft\Java Runtime Environment
key first instead of theHKLM\Software\JavaSoft\Java Development Kit
key.我在开发一个简单的 Web 服务应用程序时遇到了同样的麻烦,在我的例子中,我必须添加一个 codehous 插件才能获取 jaxws 库。然而,maven pom 不断询问工具 jar 文件。
我不得不说上面的评论是正确的,您可以在 pom 文件中包含以下条目:
但是,当您必须部署到生产实例时会发生什么?您可以用对系统环境变量的引用替换路径,但这看起来仍然不太好,至少对我来说是这样。
我在 StackOverflow 评论中找到了另一个解决方案:
Maven 3 Artifact 问题
他们建议包含一个排除声明工具罐子,它可以工作。总结一下:您可以在依赖项中包含排除规则并避免出现 tool.jar 问题:
I had the same trouble while developing a simple, web service application, in my case I had to add a codehous plug in in order to get jaxws libraries. However, maven pom kept on asking about the tools jar file.
I have to say above comments are correct, you can include the below entry in the pom file:
But, what will it happen when you have to deploy to a production instance? You could replace the path with a reference to a system environment variable but that still does not look good, at least to me.
I found another solution in a StackOverflow comment:
Maven 3 Artifact problem
They suggest including an exclusion statement for tool jar and it works. So summarizing: you can include an exclusion rule within your dependency and avoid having the tool.jar issue:
我遇到了同样的问题,解决该问题的方法是将
tools.jar
的依赖位置添加到pom.xml
中。像这样:确保将
更改为 tools.jar 文件所在的位置。I ran into the same problem and the way I was able to resolve it was add the dependency location of
tools.jar
into thepom.xml
. Like so:Make sure you change the
<systemPath>
to where ever your tools.jar file is located.其他答案都没有为我做到这一点。它的作用是检查 eclipse 中 pom.xml 的“依赖关系层次结构”,其中提供过滤器“工具”显示我对 tools.jar 有真正的依赖关系:
所以对我来说罪魁祸首是这个:
添加排除项修复了它:
排除似乎没有任何缺点。
None of the other answers did it for me. What did it was to check for "Dependency hierarchy" of the pom.xml in eclipse, where giving a filter 'tools' revealed that I had a real dependency to tools.jar:
So the culprit for me was this:
Adding an exclusion fixed it:
The exclusion doesn't seem to have any downsides to it.
我和 Windows 7 也是如此。我最终在 eclipse.ini 中添加了两行:
我尝试在那里使用 %JAVA_HOME% ,但它不起作用。
The same with me and Windows 7. I ended up adding two lines to
eclipse.ini
:I tried using
%JAVA_HOME%
there, but it did not work.我也遇到了同样的问题,
可能是由于这些原因造成的 -->
为此,您可以使用适当的 JDK(< 9) 来解决
I also ran into the same problem
can be due to any of these -->
for this you can resolve by using proper JDK(< 9)
我在 Eclipse 4.3 设置中解决了这个问题 - 仅通过将 JDK 库添加到 JRE 的库中。
转到窗口 ->设置-> Java->安装的 JRE ->选择JDK并点击编辑->单击“添加外部 JAR”并添加 tools.jar(放置在 JDK/lib 中)
I solved this problem in Eclipse 4.3 settings - only by adding JDK libraries to JRE's libraries.
Go windows -> settings -> Java -> installed JREs -> select JDK and click Edit -> click Add External JARs and add tools.jar (placed in JDK/lib)
检查您计算机上的 JDK 版本以及
pom.xml
中的 JDK 版本,两者应该相同Check the JDK version on your machine and in
pom.xml
both should be same如果此问题仍然发生,可能是因为 JDK 版本等于或大于 11。
tools.jar
存档已从这些 JDK 的 lib 文件夹中删除(请参阅 这个答案类似的问题)。在这种情况下,请尝试使用不依赖于
com.sun:tools
库的其他版本的库。If this problem still happens, it might be because of a JDK of version equal or greater than 11.
The
tools.jar
archive has been removed from the lib folder in those JDK's (see this answer to a similar question).In that case, try to use other versions of the libraries, that do not rely on the
com.sun:tools
library.如果您在新安装/升级的操作系统上看到此情况,这只是因为
JAVA_HOME
设置不正确。我们需要正确设置
JAVA_HOME
。例如在 macOS 上:如果我想使用 java 版本
1.8.0_261
:If you are seeing this on newly installed/upgraded Operating system, it is just because
JAVA_HOME
is not set properly.we need to set
JAVA_HOME
properly. For example on macOS:if I want to use java version
1.8.0_261
:经过一段时间的努力,我终于让它与 eclipse.ini 而不是命令行一起工作。最终阅读 文档 后,我意识到 -vm 参数必须位于单独的行,不加引号,位于任何 -vmargs 之前:
After struggling for a while I finally got this to work with
eclipse.ini
instead of the command line. After finally reading the documentation I realized that the -vm argument must be on a separate line, unquoted, and ahead of any -vmargs:我遇到了类似的错误。
这是因为eclipse中没有正确设置JDK。
Cucumber 需要 JDK 和 JRE,因此在 pom.xml 中添加以下依赖项
I got similar error.
This is because JDK is not properly set in eclipse.
Cucumber needs JDK along with JRE, so add below dependency in your pom.xml
在 pom 文件的有效 POM 选项卡中,我看到以下派生路径:
C:\Program Files\Java\jre6/../lib/tools.jar
我认为这不是 Windows 中的有效路径。我尝试将 tools.jar 复制到 jre6/lib 文件夹以及 Java/lib 中,但没有成功。值“C:\Program Files\Java\jre6”来自注册表
并将JavaHome键设置为您的jdk JRE安装位置。然后所有编译器错误都消失了。
重新安装JDK也没有解决。设置 JAVA_HOME 或 java.home 系统环境变量没有帮助。
我见过的另一种选择是在每个 pom xml 文件中添加正确路径的依赖项,但 playn-samples 有很多文件,编辑起来非常痛苦。
这是有效的 POM 结果,显示了错误的路径!
In the effective POM tab of the pom files, I see the following derive path:
C:\Program Files\Java\jre6/../lib/tools.jar
and I think it's not a valid path in Windows. I tried copying the tools.jar in the jre6/lib folder as well as in Java/lib without success.The value "C:\Program Files\Java\jre6" comes from the registry
And set the JavaHome key to where your jdk JRE is installed. Then all the compiler errors went away.
Reinstalling the JDK didn't fix it. Setting the JAVA_HOME or java.home system environment variable didn't help.
The other alternative I've seen is adding the dependency with the right path in each pom xml file, but the playn-samples has lots of files that is a ridiculous pain to have to edit.
This is the effective POM results, which show the WRONG path!
在 pom.xml 文件中添加此依赖项。希望这有帮助。
在
属性中,您必须编写 jdk lib 路径。Add this dependecy in pom.xml file. Hope this help.
In
<systemPath>
property you have to write your jdk lib path..最终使用 eclipse.ini 修复:
例如,
-vm C:\Java\JDK\1.6
。还必须将 JRE 更改为 JDK:
在 Eclipse IDE 中转到:
Ended up using eclipse.ini fix:
For example,
-vm C:\Java\JDK\1.6
.Had to also change JRE to JDK:
In Eclipse IDE go to:
正如其他发帖者所说,这里的问题与 eclipse 使用的 JRE 无法找到工具 jar 有关。我通过采取与上述不同的方向解决了这个问题,这是因为我的项目和环境的方式。
Eclipse 4.5 运行时至少需要 Java 7,因此我的系统设置为使用位于 C:\java\jre1.8.0_45 的 Java 8 JRE。
接下来,我使用一个 POM 文件,假设我正在使用 Java 6 JDK 运行。
我不被允许更改 POM 文件,所以我不得不做一些 jiggery pokery。我从 Java 6 JDK 复制了 tools.jar,创建了目录 C:\java\lib 并将其粘贴到那里。然后我重新启动 eclipse 并清理我的项目。瞧,错误消失了。
这不是一个优雅的解决方案,我认为正确的解决方案是更改 POM 的设置方式,但由于我无法做到这一点,所以这是可行的。
As other posters have stated the issue here has to do with the JRE that eclipse is using not being able to find the tools jar. I solved the issue by going in a bit of a different direction than what was stated above, and it was because of the way that my projects and environment.
Eclipse 4.5 requires at least Java 7 for runtime, so I've got my system setup to use a Java 8 JRE located at C:\java\jre1.8.0_45.
Next, I'm using a POM file that assumes that I'm running with a Java 6 JDK.
I'm not allowed to change the POM file, so I had to do some jiggery pokery. I copied the tools.jar from my Java 6 JDK, created the directory C:\java\lib and pasted it there. I then restarted eclipse and cleaned my project. And VOILA errors are gone.
It's not an elegant solution, and I would think that the proper solution would be to change the way the POM is setup, but as I was not able to, this works.
我在 Windows 7 和 Eclipse 3.7 上遇到了同样的问题
我设法通过开始修复它
您可以像这样启动 cmd 并启动 eclipse,或者您可以编辑快捷方式并添加 -vm "D:\JDK6\bin" 作为“目标部分”中的参数”。
作为旁注,我还尝试将 -vm "D:\JDK6\bin" 添加到 eclipse.ini 但没有成功。
添加 JRE6 将不起作用,因为它的“lib”目录中不包含 tools.jar。只有 JDK 可以。
I had the same problem on a Windows 7 and Eclipse 3.7
I managed to fix it by starting
You can start a cmd and launch eclipse like that, or you can edit your shortcut and add -vm "D:\JDK6\bin" as an argument in the "target section".
As a sidenote, I also tried to add -vm "D:\JDK6\bin" to eclipse.ini but did not work.
And adding JRE6 will not work since it does NOT contain tools.jar in it's "lib" directory. Only JDK does.
尝试了以上所有方法后,我仍然遇到同样的问题。
然后我尝试了以下操作,
打开命令提示符并键入 java -version。它向我显示了 JRE 版本 1.8。
打开命令提示符并转到 JDK 1.7 bin 目录的位置并键入 java -version。这次它正确显示了 1.7。
然后,在挖掘了几个地方之后,我发现除了上述位置之外,还有其他 Java 运行时位置。
注册表
还有一个注册表项,在其中指定 JRE 位置
我更改了此处的条目以指向 JDK 1.7
ProgramData
目录“C:\ProgramData\Oracle\Java\javapath”存在于 PATH 环境变量中,并包含java、javaw 等...
这些快捷方式的目标都是 JRE 1.8。 (我认为这是主要问题)
我更改了快捷方式以指向正确的 JDK exe。
一旦这一切都完成了。我打开 eclipse 所有 jdk.tools pom.xml 错误都消失了。
After trying out all the above I was still having the same issue.
Then I tried the following,
Open a command prompt and typed java -version. It showed me a JRE version 1.8.
Open a command prompt and went to location of the JDK 1.7 bin directory and typed java -version. This time it showed correctly 1.7.
Then after digging at few places I found that apart from the above locations there are additional locations for Java runtime.
Registry
There is also a registry key where JRE location are specified under
I changed the entries here to point to the JDK 1.7
ProgramData
The directory "C:\ProgramData\Oracle\Java\javapath" is present in PATH environment variable and contains shortcuts to the java, javaw etc...
The target for these shortcuts were all JRE 1.8. (This I think was the main problem)
I changed the shortcuts to point to the correct JDK exe's.
Once all of this was done. I opened eclipse all the jdk.tools pom.xml errors disappeared.
我遇到了这个问题,结果发现 Windows 上的 JBossDevStudio 9.1 是一个 32 位程序。 Eclipse 以及 JBossDevStudio 无法使用错误类型的 JVM。 64位eclipse需要64位JVM,32位eclipse需要32位JVM。因此,将 Eclipse 配置为与我安装的 64 位 JDK 一起运行并不起作用。
安装 32 位 JDK 并从中运行 Eclipse 解决了问题。
至少对于我的一个项目来说,另一个我尝试在 Eclipse 项目属性中配置运行时 JDK 的项目仍然损坏。
I got this problem and it turns out that JBossDevStudio 9.1 on Windows is a 32-bit program. Eclipse, and thus the JBossDevStudio, does not work with the wrong type of JVM. 64-bit eclipse needs a 64-bit JVM, 32-bit eclipse needs a 32-bit JVM. Thus configuring Eclipse to run with my installed 64-bit JDK did not work.
Installing a 32 bit JDK and running Eclipse from that solved the problem.
At least for one of my projects, an other where I had tried to configure a runtime JDK in the Eclipse project properties is still broken.
我通过从系统中卸载 JRE 并仅保留 JDK 解决了该问题。重新安装 JDK 是不够的,因为 Oracle JDK 安装程序同时安装 JDK 和 JRE
顺便说一句,在我看来,这个错误是造成麻烦的原因: 使用 Eclipse JRE 的 java.home 代替构建 JRE
I solved the problem by uninstalling JRE from my system and leaving JDK only. Reinstall JDK is not enough because Oracle JDK installer installs both JDK and JRE
BTW, it seems to me that this bug is responsible for troubles: java.home of the Eclipse JRE is used instead of the build JRE
就我而言,我是从 Eclipse 运行配置执行 Maven 构建。即使将默认 JRE 配置更改为指向 JDK 安装文件夹后,问题也没有得到解决。原因是Maven Build - Run Configuration中有一个JRE选项卡(见下图)。它仍然指向我的 JRE 安装。我将其更改为指向 JDK 安装,然后运行 Maven Build。这一次,它成功了。
在此处输入图片说明
In my case, I was executing Maven Build from Eclipse Run Configurations. Even after changing the default JRE configuration to point to JDK installation folder, the issue didn't get fixed for me. The reason is that there is a JRE tab in the Maven Build - Run Configuration (see the image below). And it was still pointing to my JRE installation. I changed it to point to JDK installation and then ran the Maven Build. This time, it worked.
enter image description here
让我们了解一下为什么会出现这个问题:
Maven“mvn -version”命令返回以上输出。
如果不指定 JAVA_HOME 环境变量,我们可以看到 maven 获取的 java 运行时路径为“C:\Program Files\Java\jre1.8.0_221”。然后maven假设这个路径是JAVA_HOME。这就是为什么当从命令提示符或任何 IDE 构建应用程序时,maven 在路径“%JAVA_HOME%..\lib\tools.jar”中查找 tools.jar 文件。
tools.jar 存在于 JDK 路径中,因此我们需要在使用它之前向 Maven 提及它。现在,机器是用已经可用的 jre 构建的,但 jdk 仅在开发时需要。这可能就是maven自动选择jre路径的原因。
如需更多帮助,请阅读maven安装路径中提供的代码mvn.cmd。
Let's understand why this issue happened:
Maven "mvn -version" command returns above output.
We can see maven gets the java runtime path as "C:\Program Files\Java\jre1.8.0_221" if you don't specify JAVA_HOME environment variable. And then maven assumes this path to be JAVA_HOME. That's why when building the application either from command prompt or any IDE, maven looks for tools.jar file in path "%JAVA_HOME%..\lib\tools.jar".
tools.jar is present in JDK path, so we need to mention this to maven before using it. Now a days machines are build with already available jre, but jdk is only required for development. This might be the reason why maven picks jre path automatically.
For more help, please read the code mvn.cmd available in maven installation path.
问题是系统无法找到文件tools.jar,
因此首先检查该文件是否位于JDK安装目录中。
按照其他人的正确指示,在 POM.xml 中添加以下条目
,然后按照以下步骤也可以消除问题
1) 右键单击您的项目
2) 单击“构建”路径
如下图所示,选择工作区默认 JRE 并单击完成。
Problem is system is not able to find the file tools.jar
So first check that the file is there in the JDK installation of the directory.
Make the below entry in POM.xml as rightly pointed by others
then Follow the below steps also to remove the problem
1) Right Click on your project
2) Click on Build path
As per the below image, select the workspace default JRE and click on finish.
在“首选项 ->”下更改“已安装的 JRE” Java->将 JRE 安装到 JDK home 对我有用。
仅供参考 - 我正在使用 JDK 1.8。
Changing 'Installed JREs' under 'Preferences -> Java -> Installed JRE' to JDK home worked for me.
FYI - Am using JDK 1.8.
我相信这些本地补丁会起作用。然而,这些可能会导致下游部署问题。我只是下载了带有 Java 11 的新版本 Eclipse,现在一切正常。
I believe these local patches will work. However these likely to cause downstream deployment issues. I simply downloaded a new version of Eclipse with Java 11, now everything works fine.
另一种情况
JAVA_HOME
变量必须指向 Java 11+ 安装。解决方案
mvn
shell 脚本(Windows 上为mvn.bat
或mvn.cmd
)并将JAVA_HOME
设置为指向 JDK 8 安装。Another scenario
JAVA_HOME
variable must point to a Java 11+ installation.A solution
mvn
shell script (mvn.bat
ormvn.cmd
on Windows) and setJAVA_HOME
to point to a JDK 8 installation.将
${java.home}/../lib/tools.jar
的相对位置更改为绝对路径C:\Program Files\Java\jdk1.6.0_29\lib\tools.jar
对我有用。您只需在
playn/pom.xml
中更改它。现在对于 playn-samples,Vladiator 是对的,需要更改的 pom 文件太多。
Changing the relative location of
${java.home}/../lib/tools.jar
to the absolute pathof
C:\Program Files\Java\jdk1.6.0_29\lib\tools.jar
works for me.You should only have to change it in the
playn/pom.xml
.Now for the playn-samples, Vladiator is right, that's too many pom files to change.