简体   繁体   English

在 java 项目的 pom.xml 中,我缺少工件 jdk.tools:jdk.tools:jar:1.6 错误

[英]In the pom.xml for a java project, I get missing artifact jdk.tools:jdk.tools:jar:1.6 error

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 “想要”我机器上实际拥有的工具版本?

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.当使用 JRE 而不是 JDK 启动 eclipse 时会发生这种情况,因为tools.jar不在 JRE 中。 Based on that assertion, try installing the JDK.基于该断言,尝试安装 JDK。 If it's already installed, check in your Path that you have the JDK path and not the JRE path.如果它已经安装,请检查您的Path是否有 JDK 路径而不是 JRE 路径。

Be careful, the latest versions of java seems to add in the Path the following directory: C:\ProgramData\Oracle\Java\javapath .注意,最新版本的 java 似乎在Path中添加了以下目录: C:\ProgramData\Oracle\Java\javapath It contains shortcuts that may link to the JRE.它包含可能链接到 JRE 的快捷方式。 You'll want to remove that and add in the link to your JDK bin folder.您需要删除它并添加指向 JDK bin 文件夹的链接。 (eg C:\Program Files\Java\jdk1.8.0_66\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.另请注意,Java 更新可能会将javapath重新添加到您的 PATH 中。 So you may want not to use auto-updates but instead manually update your JDK and adapt your path after the install.因此,您可能不想使用自动更新,而是手动更新 JDK 并在安装后调整路径。 It's a bit heavy but does the work.它有点重,但确实有效。

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:此问题出现在以下两种情况之一中:

  1. You do not have JDK installed and configured;您没有安装和配置 JDK; or或者

  2. You've both JDK and JRE installed and JRE is getting precedence over the JDK path.您已经安装了 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”团队在此链接中所解释的那样,您只需将依赖项添加到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, 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>

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

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>

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

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.这立即解决了我的问题。

For the benefit of those who Google this error when encountering it in 2021 (many years after the OP... yikes) and are using a modern openjdk distribution, it is possible to exclude jdk.tools from individual dependencies like so:为了那些在 2021 年(在 OP 之后很多年)遇到此错误并使用现代 openjdk 发行版的人的利益,可以将jdk.tools从单个依赖项中排除,如下所示:

<dependency>
    <groupId>org.apache.systemds</groupId>
    <artifactId>systemds</artifactId>
    <version>2.1.0</version>
    <exclusions>
        <exclusion>
            <artifactId>jdk.tools</artifactId>
            <groupId>jdk.tools</groupId>
        </exclusion>
    </exclusions>
</dependency>

Admittedly I'm not sure of the general consequences of this, but it is useful in the situations I've needed it (eg when running mvn dependency:copy-dependencies )诚然,我不确定这样做的一般后果,但它在我需要它的情况下很有用(例如,在运行mvn dependency:copy-dependencies时)

<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>

Add this code to the dependencies pom.xml:将此代码添加到依赖项 pom.xml:

<dependency>
   <groupId>org.apache.solr</groupId>
   <artifactId>solr-core</artifactId>
   <version>4.5.1</version>
   <exclusions>
      <exclusion>
         <artifactId>jdk.tools</artifactId>
         <groupId>jdk.tools</groupId>
      </exclusion>
   </exclusions>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM