缺少工件 com.sun:tools:jar

发布于 2024-12-19 05:45:27 字数 2561 浏览 2 评论 0原文

我一直在关注入门教程,但在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(27

第七度阳光i 2024-12-26 05:45:27

我刚刚在这个问题上发布了关于同一问题以及我如何解决了它,但我也会将其粘贴(并扩展)在这里,因为它看起来更相关。

在 Windows 7 中使用 Eclipse 时,我遇到了同样的问题,即使我从 Eclipse 设置中的 JRE 列表中删除了 JRE,而只保留了 JDK。

我最终要做的(正如您在问题中提到的)是修改我用来启动 Eclipse 的快捷方式的命令行,以添加 -vm 参数,如下所示:

-vm "T:\Program Files\Java\jdk1.6.0_26\bin"

当然,您可以将其调整为指向 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:

-vm "T:\Program Files\Java\jdk1.6.0_26\bin"

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 the HKLM\Software\JavaSoft\Java Development Kit key.

空名 2024-12-26 05:45:27

我在开发一个简单的 Web 服务应用程序时遇到了同样的麻烦,在我的例子中,我必须添加一个 codehous 插件才能获取 jaxws 库。然而,maven pom 不断询问工具 jar 文件。

我不得不说上面的评论是正确的,您可以在 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>

但是,当您必须部署到生产实例时会发生什么?您可以用对系统环境变量的引用替换路径,但这看起来仍然不太好,至少对我来说是这样。

我在 StackOverflow 评论中找到了另一个解决方案:

Maven 3 Artifact 问题

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts2.version}</version>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>
</dependency>

他们建议包含一个排除声明工具罐子,它可以工作。总结一下:您可以在依赖项中包含排除规则并避免出现 tool.jar 问题:

 <exclusions>
            <exclusion>
                <artifactId>tools</artifactId>
                <groupId>com.sun</groupId>
            </exclusion>
        </exclusions>

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:

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

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts2.version}</version>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>
</dependency>

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:

 <exclusions>
            <exclusion>
                <artifactId>tools</artifactId>
                <groupId>com.sun</groupId>
            </exclusion>
        </exclusions>
苏璃陌 2024-12-26 05:45:27

我遇到了同样的问题,解决该问题的方法是将 tools.jar 的依赖位置添加到 pom.xml 中。像这样:

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

确保将 更改为 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 the pom.xml. Like so:

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

Make sure you change the <systemPath> to where ever your tools.jar file is located.

翻了热茶 2024-12-26 05:45:27

其他答案都没有为我做到这一点。它的作用是检查 eclipse 中 pom.xml 的“依赖关系层次结构”,其中提供过滤器“工具”显示我对 tools.jar 有真正的依赖关系:

Eclipse View

所以对我来说罪魁祸首是这个:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.4.0.7</version>
    <scope>test</scope>
</dependency>

添加排除项修复了它:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.4.0.7</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>  
</dependency>

排除似乎没有任何缺点。

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:

Eclipse View

So the culprit for me was this:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.4.0.7</version>
    <scope>test</scope>
</dependency>

Adding an exclusion fixed it:

<dependency>
    <groupId>com.github.markusbernhardt</groupId>
    <artifactId>robotframework-selenium2library-java</artifactId>
    <version>1.4.0.7</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>  
</dependency>

The exclusion doesn't seem to have any downsides to it.

看透却不说透 2024-12-26 05:45:27

我和 Windows 7 也是如此。我最终在 eclipse.ini 中添加了两行:

-vm 
C:\Program Files\Java\jdk1.6.0_35\bin

我尝试在那里使用 %JAVA_HOME% ,但它不起作用。

The same with me and Windows 7. I ended up adding two lines to eclipse.ini:

-vm 
C:\Program Files\Java\jdk1.6.0_35\bin

I tried using %JAVA_HOME% there, but it did not work.

小梨窩很甜 2024-12-26 05:45:27

我也遇到了同样的问题,

可能是由于这些原因造成的 -->

  1. 您安装的是 JRE 而不是 JDK。 (继续安装 JDK )
  2. JDK 路径配置不正确或者您的 IDE 使用了完全错误的 SDK(如果是 Intellij,请参阅项目结构)
  3. 您使用了错误的 JDK 版本,tools.jar 已被删除从版本 9 开始使用 jdk (https://docs.oracle.com/en/java/javase/13/migrate/migration-guide.pdf
    为此,您可以使用适当的 JDK(< 9) 来解决
    来自 Oracle 的屏幕截图迁移文档

I also ran into the same problem

can be due to any of these -->

  1. You have installed JRE instead of JDK. (Go ahead and install JDK )
  2. JDK Path is not configured properly or your IDE is using a completely wrong SDK (See project Structure in case of Intellij)
  3. You are using wrong JDK Version , tools.jar was removed from jdk since version 9 (https://docs.oracle.com/en/java/javase/13/migrate/migration-guide.pdf)
    for this you can resolve by using proper JDK(< 9)
    Screenshot from Oracle migration doc
晨曦慕雪 2024-12-26 05:45:27

我在 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)

眸中客 2024-12-26 05:45:27

检查您计算机上的 JDK 版本以及 pom.xml 中的 JDK 版本,两者应该相同

<dependency>
    <groupId>sun.jdk</groupId>
    <artifactId>tools</artifactId>
    <version>1.8</version>
    <scope>system</scope>
    <systemPath>C:\Program Files\Java\jdk1.8.0_192\lib\tools.jar</systemPath>
</dependency>

Check the JDK version on your machine and in pom.xml both should be same

<dependency>
    <groupId>sun.jdk</groupId>
    <artifactId>tools</artifactId>
    <version>1.8</version>
    <scope>system</scope>
    <systemPath>C:\Program Files\Java\jdk1.8.0_192\lib\tools.jar</systemPath>
</dependency>
秉烛思 2024-12-26 05:45:27

如果此问题仍然发生,可能是因为 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.

在巴黎塔顶看东京樱花 2024-12-26 05:45:27

如果您在新安装/升级的操作系统上看到此情况,这只是因为 JAVA_HOME 设置不正确。

我们需要正确设置JAVA_HOME。例如在 macOS 上:

如果我想使用 java 版本 1.8.0_261

export JAVA_HOME=`/usr/libexec/java_home -v 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:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`
少女情怀诗 2024-12-26 05:45:27

经过一段时间的努力,我终于让它与 eclipse.ini 而不是命令行一起工作。最终阅读 文档 后,我意识到 -vm 参数必须位于单独的行,不加引号,位于任何 -vmargs 之前:

-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe

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:

-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe
神魇的王 2024-12-26 05:45:27

我遇到了类似的错误。
这是因为eclipse中没有正确设置JDK。
Cucumber 需要 JDK 和 JRE,因此在 pom.xml 中添加以下依赖项

<dependency>
  <groupId>com.sun</groupId>
  <artifactId>tools</artifactId>
  <version>1.6</version>
  <scope>system</scope>
  <systemPath>C:\Program Files\Java\jdk1.8.0_101\lib\tools.jar</systemPath>
</dependency>

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

<dependency>
  <groupId>com.sun</groupId>
  <artifactId>tools</artifactId>
  <version>1.6</version>
  <scope>system</scope>
  <systemPath>C:\Program Files\Java\jdk1.8.0_101\lib\tools.jar</systemPath>
</dependency>
宫墨修音 2024-12-26 05:45:27

在 pom 文件的有效 POM 选项卡中,我看到以下派生路径:
C:\Program Files\Java\jre6/../lib/tools.jar 我认为这不是 Windows 中的有效路径。我尝试将 tools.jar 复制到 jre6/lib 文件夹以及 Java/lib 中,但没有成功。

值“C:\Program Files\Java\jre6”来自注册表

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6.0_30
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6

并将JavaHome键设置为您的jdk JRE安装位置。然后所有编译器错误都消失了。

重新安装JDK也没有解决。设置 JAVA_HOME 或 java.home 系统环境变量没有帮助。

我见过的另一种选择是在每个 pom xml 文件中添加正确路径的依赖项,但 playn-samples 有很多文件,编辑起来非常痛苦。

这是有效的 POM 结果,显示了错误的路径!

 <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.6</version>
      <scope>system</scope>
      <systemPath>C:\Program Files\Java\jre6/../lib/tools.jar</systemPath>
      <optional>true</optional>
    </dependency>

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

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6.0_30
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6

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!

 <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.6</version>
      <scope>system</scope>
      <systemPath>C:\Program Files\Java\jre6/../lib/tools.jar</systemPath>
      <optional>true</optional>
    </dependency>
三生池水覆流年 2024-12-26 05:45:27

在 pom.xml 文件中添加此依赖项。希望这有帮助。
属性中,您必须编写 jdk lib 路径。

    <dependency>  
          <groupId>com.sun</groupId> 
           <artifactId>tools</artifactId>
        <version>1.4.2</version>
        <scope>system</scope>
        <systemPath>C:/Program Files/Java/jdk1.6.0_30/lib/tools.jar</systemPath>
        </dependency> 

Add this dependecy in pom.xml file. Hope this help.
In <systemPath> property you have to write your jdk lib path..

    <dependency>  
          <groupId>com.sun</groupId> 
           <artifactId>tools</artifactId>
        <version>1.4.2</version>
        <scope>system</scope>
        <systemPath>C:/Program Files/Java/jdk1.6.0_30/lib/tools.jar</systemPath>
        </dependency> 
美羊羊 2024-12-26 05:45:27

最终使用 eclipse.ini 修复:

openFile
-vm (Your Java Home JDK here)

例如,-vm C:\Java\JDK\1.6

还必须将 JRE 更改为 JDK:

在 Eclipse IDE 中转到:

  1. Window ->首选项->安装的 JRE
  2. 单击“添加”(以找到新的 JRE)
  3. 选择标准 JVM ->接下来
  4. 单击“目录”找到 JRE 主目录,放入 JDK_INSTALL_LOCATION 并完成。
  5. 转到您的 java 项目的属性 -> Java构建路径->图书馆 ->选择JRE->编辑->选择工作区默认JRE ->完成
  6. 对项目进行完整的工作区清理 ->干净的。

Ended up using eclipse.ini fix:

openFile
-vm (Your Java Home JDK here)

For example, -vm C:\Java\JDK\1.6.

Had to also change JRE to JDK:

In Eclipse IDE go to:

  1. Window -> Preferences -> Installed JREs
  2. Click on Add (to locate new JRE)
  3. Select standard JVM -> next
  4. Click on Directory to locate JRE home, put JDK_INSTALL_LOCATION and finish.
  5. Go to your java project's Properties -> Java build Path -> Libraries -> select JRE -> Edit -> select Workspace default JRE -> finish
  6. Do a full workspace cleanup with project -> clean.
痴情 2024-12-26 05:45:27

正如其他发帖者所说,这里的问题与 eclipse 使用的 JRE 无法找到工具 jar 有关。我通过采取与上述不同的方向解决了这个问题,这是因为我的项目和环境的方式。

Eclipse 4.5 运行时至少需要 Java 7,因此我的系统设置为使用位于 C:\java\jre1.8.0_45 的 Java 8 JRE。

接下来,我使用一个 POM 文件,假设我正在使用 Java 6 JDK 运行。

  <profiles>
    <profile>
      <id>default-profile</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <file>
          <exists>${java.home}/../lib/tools.jar</exists>
        </file>
      </activation>
      <properties>
        <toolsjar>${java.home}/../lib/tools.jar</toolsjar>
      </properties>
    </profile>
    <profile>
      <id>osx_profile</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <os>
          <family>mac</family>
        </os>
      </activation>
      <properties>
        <toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
      </properties>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.6.0</version>
      <scope>system</scope>
      <systemPath>${toolsjar}</systemPath>
    </dependency>
  </dependencies>

我不被允许更改 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.

  <profiles>
    <profile>
      <id>default-profile</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <file>
          <exists>${java.home}/../lib/tools.jar</exists>
        </file>
      </activation>
      <properties>
        <toolsjar>${java.home}/../lib/tools.jar</toolsjar>
      </properties>
    </profile>
    <profile>
      <id>osx_profile</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <os>
          <family>mac</family>
        </os>
      </activation>
      <properties>
        <toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
      </properties>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.6.0</version>
      <scope>system</scope>
      <systemPath>${toolsjar}</systemPath>
    </dependency>
  </dependencies>

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.

漆黑的白昼 2024-12-26 05:45:27

我在 Windows 7 和 Eclipse 3.7 上遇到了同样的问题
我设法通过开始修复它

eclipse.exe -vm "D:\JDK6\bin"

您可以像这样启动 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

eclipse.exe -vm "D:\JDK6\bin"

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.

安静被遗忘 2024-12-26 05:45:27

尝试了以上所有方法后,我仍然遇到同样的问题。

  • PATH 环境变量指向 JDK 1.7\bin
  • 我的 JAVA_HOME 环境变量指向 JDK 1.7
  • 我的 eclipse.ini 有 javaw -vm 条目指向 JDK 1.7
  • 我的 eclipse 首选项将 JDK 1.7 作为已安装的 JRE。
  • 我的项目构建路径使用 JDK 1.7。

然后我尝试了以下操作,

  • 打开命令提示符并键入 java -version。它向我显示了 JRE 版本 1.8。

  • 打开命令提示符并转到 JDK 1.7 bin 目录的位置并键入 java -version。这次它正确显示了 1.7。

然后,在挖掘了几个地方之后,我发现除了上述位置之外,还有其他 Java 运行时位置。

注册表

还有一个注册表项,在其中指定 JRE 位置

HKLM\软件\Javasoft\版本

我更改了此处的条目以指向 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.

  • PATH environment variable point to JDK 1.7\bin
  • My JAVA_HOME environment variable was pointed to the JDK 1.7
  • My eclipse.ini had the javaw -vm entry pointing to JDK 1.7
  • My eclipse preference had JDK 1.7 as the installed JRE.
  • My project build path was using JDK 1.7.

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

HKLM\Software\Javasoft\Version

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.

篱下浅笙歌 2024-12-26 05:45:27

我遇到了这个问题,结果发现 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.

余生再见 2024-12-26 05:45:27

我通过从系统中卸载 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

喜爱皱眉﹌ 2024-12-26 05:45:27

就我而言,我是从 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

ぶ宁プ宁ぶ 2024-12-26 05:45:27

让我们了解一下为什么会出现这个问题:

$ mvn -版本

<块引用>
Apache Maven 3.6.1(d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555;2019-04-04T20:00:29+01:00)
Maven 主目录:C:\Program Files\Apache\maven-3.6.1
Java 版本:1.8.0_221,供应商:Oracle Corporation,运行时:C:\Program Files\Java\jre1.8.0_221
默认区域设置:en_GB,平台编码:Cp1252
操作系统名称:“windows 10”,版本:“10.0”,架构:“amd64”,系列:“windows”

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:

$ mvn -version

Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T20:00:29+01:00)
Maven home: C:\Program Files\Apache\maven-3.6.1
Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_221
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

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.

作业与我同在 2024-12-26 05:45:27

问题是系统无法找到文件tools.jar

因此首先检查该文件是否位于JDK安装目录中。

输入图片此处描述

按照其他人的正确指示,在 POM.xml 中添加以下条目

<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>C:\Program Files\Java\jdk1.8.0_241\lib\tools.jar</systemPath>
</dependency> 

,然后按照以下步骤也可以消除问题

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.

enter image description here

Make the below entry in POM.xml as rightly pointed by others

<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>C:\Program Files\Java\jdk1.8.0_241\lib\tools.jar</systemPath>
</dependency> 

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.

enter image description here

小傻瓜 2024-12-26 05:45:27

在“首选项 ->”下更改“已安装的 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.

谈场末日恋爱 2024-12-26 05:45:27

我相信这些本地补丁会起作用。然而,这些可能会导致下游部署问题。我只是下载了带有 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.

若相惜即相离 2024-12-26 05:45:27

另一种情况

  • JAVA_HOME 变量必须指向 Java 11+ 安装。
  • 老项目中使用Maven。新项目使用 Gradle。
  • 旧的 Maven 项目使用 Java 8,如果我们使用 Java 9+,其中一些项目会因缺少 tools.jar 文件错误而中断。

解决方案

  • 编辑 mvn shell 脚本(Windows 上为 mvn.batmvn.cmd)并将 JAVA_HOME 设置为指向 JDK 8 安装。
  • 该脚本位于 apache maven 安装下的 /bin 目录中。
  • 设置变量的位置示例(Windows 脚本):
    @REM ==== START VALIDATION ====
    set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161

Another scenario

  • The JAVA_HOME variable must point to a Java 11+ installation.
  • Maven is used in old projects. New projects use Gradle.
  • Old maven projects use Java 8 and some of them break with the missing tools.jar file error if we use Java 9+.

A solution

  • Edit the mvn shell script (mvn.bat or mvn.cmd on Windows) and set JAVA_HOME to point to a JDK 8 installation.
  • The script is in the /bin directory under your apache maven installation.
  • Example of where to set the variable (Windows script):
    @REM ==== START VALIDATION ====
    set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
与之呼应 2024-12-26 05:45:27

${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 path
of 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文