在 java 项目的 pom.xml 中,我丢失了工件 jdk.tools:jdk.tools:jar:1.6 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29195269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In the pom.xml for a java project, I get missing artifact jdk.tools:jdk.tools:jar:1.6 error
提问by Jeff
I think I know how to solve the problem except: I don't know where in the pom the specific version is referred to (I do not see it explicitly) and the solution I have seen is to add this dependency:
我想我知道如何解决这个问题,除了:我不知道特定版本在 pom 中的何处被引用(我没有明确看到它),我看到的解决方案是添加这个依赖项:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>C:\Program Files\Java\jdk1.6.0_29\lib\tools.jar</systemPath>
</dependency>
But I would like to use com.oracle and the jdk directory on Windows is jdk1.8.
但是我想用com.oracle,windows上的jdk目录是jdk1.8。
So is there a way to make the pom "want" the version of tools that I actually have on my machine?
那么有没有办法让 pom “想要”我机器上实际拥有的工具版本?
采纳答案by Crystark
I finally tackled this the proper way.
我终于以正确的方式解决了这个问题。
This happens when eclipse is launched with the JRE instead of the JDK as tools.jar
isn't in the JRE.
Based on that assertion, try installing the JDK. If it's already installed, check in your Path
that you have the JDK path and not the JRE path.
当使用 JRE 而不是 JDK 启动 eclipse 时会发生这种情况,因为tools.jar
它不在 JRE 中。根据该断言,尝试安装 JDK。如果已经安装,请检查您Path
是否拥有 JDK 路径而不是 JRE 路径。
Be careful, the latest versions of java seems to add in the Path
the following directory: C:\ProgramData\Oracle\Java\javapath
. It contains shortcuts that may link to the JRE. You'll want to remove that and add in the link to your JDK bin folder. (e.g. C:\Program Files\Java\jdk1.8.0_66\bin
)
注意,最新版本的java好像Path
在下面的目录中添加了:C:\ProgramData\Oracle\Java\javapath
. 它包含可以链接到 JRE 的快捷方式。您需要删除它并添加指向 JDK bin 文件夹的链接。(例如C:\Program Files\Java\jdk1.8.0_66\bin
)
Note that you may need to restart your computer for the changes in the Path
to be effective for the eclipse launch (I don't really understand why I had to but I did).
请注意,您可能需要重新启动计算机以使Path
Eclipse 启动中的更改生效(我真的不明白为什么我必须这样做,但我做到了)。
Also note that Java updates will probably re-add the javapath
to your PATH. So you may want not to use auto-updates but instead manually update your JDK and adapt your path after the install. It's a bit heavy but does the work.
另请注意,Java 更新可能会将 重新添加javapath
到您的 PATH。因此,您可能不想使用自动更新,而是在安装后手动更新 JDK 并调整路径。它有点重,但可以工作。
回答by dosyfier
You can use the "java.home" environment variable :
您可以使用“java.home”环境变量:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/lib/tools.jar</systemPath>
</dependency>
Please have a look to : https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
请查看:https: //maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
回答by smita
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>C:/jdk1.7.0_51/lib/tools.jar</systemPath>
</dependency>
回答by Vikram Deshmukh
For anyone who stumbles over this issue in the future, read on for a more elegant solution:
对于将来遇到此问题的任何人,请继续阅读以获取更优雅的解决方案:
Reason
原因
This issue crops up in one of the two scenarios:
此问题出现在以下两种情况之一中:
You do not have JDK installed and configured; or
You've both JDK and JRE installed and JRE is getting precedence over the JDK path.
你没有安装和配置JDK;或者
您已经安装了 JDK 和 JRE,并且 JRE 的优先级高于 JDK 路径。
Solution
解决方案
As explained in this link by the team at 'Hadoop in the real world', you merely need to add the dependency to tools.jar
in your pom.xml
file.
正如'Hadoop in the real world' 团队在此链接中所解释的,您只需要tools.jar
在pom.xml
文件中添加依赖项即可。
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7.0_05</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
If the error persists, then just change the path to tools.jar
to an absolute path as shown below:
如果错误仍然存在,则只需将路径更改为tools.jar
绝对路径,如下所示:
<systemPath>C:/Program Files/Java/jdk1.8.0_65/lib/tools.jar</systemPath>
回答by Gautam
As I figured the best way to tackle this is to add the following configuration to your eclipse.ini to make sure it uses the jdk copy of javaw while running eclipse instead of the JRE copy which solves the problem and seems to be the correct approach to fix the issue
正如我认为解决这个问题的最好方法是将以下配置添加到您的 eclipse.ini 以确保它在运行 eclipse 时使用 javaw 的 jdk 副本而不是解决问题的 JRE 副本,这似乎是解决问题的正确方法解决问题
-vm
C:/Program Files/Java/jdk1.8.0_73/bin/javaw.exe
回答by Mithun B
I figured out the solution to this problem in eclipse.
我在eclipse中找到了解决这个问题的方法。
In Eclipse,
在日食中,
Navigate to Window -> Preferences
导航到窗口 -> 首选项
On the left hand pane, expand Java and you will find the "Installed JREs" entry
在左侧窗格中,展开 Java,您将找到“已安装的 JRE”条目
Select that and you should be able to see the JRE entry that is referring to the JRE folder rather than the JDK folder.
选择它,您应该能够看到引用 JRE 文件夹而不是 JDK 文件夹的 JRE 条目。
Select the entry to edit it and then redirect it to the JDK folder and click on Apply.
选择条目进行编辑,然后将其重定向到 JDK 文件夹并单击应用。
This solved my problem right away.
这立即解决了我的问题。
回答by Govinda Hinduja
you merely need to add the dependency to tools.jar in your pom.xml file.
您只需要在 pom.xml 文件中将依赖项添加到 tools.jar。
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7.0_05</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
If the error persists, change the path to tools.jar to an absolute path as shown below:
如果错误仍然存在,请将 tools.jar 的路径更改为绝对路径,如下所示:
<systemPath>C:/Program Files/Java/jdk1.8.0_65/lib/tools.jar</systemPath>