Java 编译致命错误:找不到tools.jar - maven-compiler-plugin
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29234759/
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
Fatal error compiling: tools.jar not found - maven-compiler-plugin
提问by Tom Dory
Issue: The following problem occurs when I compile my project w/ maven (note: I'm working on windows):
问题:当我使用 maven 编译我的项目时会出现以下问题(注意:我在 Windows 上工作):
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project XYZ: Fatal error compiling: tools.jar not found: C:\java\jdk1.8.0_40..\lib\tools.jar -> [Help 1]
无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project XYZ: Fatal error compiling: tools.jar not found: C:\java\jdk1.8.0 _40..\lib\tools.jar -> [帮助 1]
Error occurs from both command line and eclipse (Eclipse STS) - mvn clean; mvn install
命令行和 Eclipse (Eclipse STS) 均出现错误 - mvn clean; 安装
Notes:
笔记:
- System env variable, JAVA_HOME, was set to C:\java\jdk1.8.0_40
- C:\java\jdk1.8.0_40\lib\tools.jar is there
- Tried clearing local maven repo (.m2) - error still occurred
- configured maven compiler plugin to point to C:/java/jdk1.7.0_75/bin/javac.exe executable with source=target=1.7 - same error
- Tried installing java 1.7.0_75 in eclipse and using that (but maven is still used for the compile -- right-click on project, run as, maven install): same error (even with maven compiler's plugin configuration's executable set to C:/java/jdk1.7.0_75/bin/javac.exe)
- 系统环境变量 JAVA_HOME 设置为 C:\java\jdk1.8.0_40
- C:\java\jdk1.8.0_40\lib\tools.jar 在那里
- 尝试清除本地 maven repo (.m2) - 仍然发生错误
- 配置 maven 编译器插件以指向 C:/java/jdk1.7.0_75/bin/javac.exe 可执行文件, source=target=1.7 - 同样的错误
- 尝试在 eclipse 中安装 java 1.7.0_75 并使用它(但 maven 仍用于编译——右键单击项目,运行方式,maven install):相同的错误(即使 maven 编译器的插件配置的可执行文件设置为 C:/ java/jdk1.7.0_75/bin/javac.exe)
回答by Tom Dory
Issue resolved: Setting System env variable, JAVA_HOME, to Java JDK 1.7 fixed the problem.
已解决的问题:将系统环境变量 JAVA_HOME 设置为 Java JDK 1.7 解决了该问题。
I tried jdk1.7.0_45 and jdk1.7.0_75 - they both worked.
我试过 jdk1.7.0_45 和 jdk1.7.0_75 - 它们都有效。
Notes:
笔记:
- I thought setting the compiler executable for the compiler plugin in
pom.xml would mean that the executable was used in all cases;
apparently it's not - the JAVA_HOME variable overrode it in this
case. - Some other folks had issues b/c their JAVA_HOME was set to a JRE instead of a JDK. My JAVA_HOME for Java 1.8 was set to JDK 1.8, but I still received the same error.
- 我认为在 pom.xml 中为编译器插件设置编译器可执行文件意味着在所有情况下都使用该可执行文件;
显然不是 - 在这种
情况下JAVA_HOME 变量覆盖了它。 - 其他一些人有问题 b/c 他们的 JAVA_HOME 被设置为 JRE 而不是 JDK。我的 Java 1.8 JAVA_HOME 设置为 JDK 1.8,但我仍然收到相同的错误。
回答by Liju John
I also faced similar issue when building the project in eclipse ( sts version) I figured out the issue was because I had jre installed in 2 locations and I jre configured in the eclipse was pointing to the pure jre folder. So just check that your jre is pointing to the jre folder inside the jdk not any other jre as the tools.jar is in jdk/lib
在 eclipse(sts 版本)中构建项目时,我也遇到了类似的问题,我发现问题是因为我在 2 个位置安装了 jre,而我在 eclipse 中配置的 jre 指向了纯 jre 文件夹。因此,只需检查您的 jre 是否指向 jdk 中的 jre 文件夹,而不是其他任何 jre,因为 tools.jar 位于 jdk/lib 中
回答by Vijayaraghavan
If tools.jar is not found, try adding it up in your project's dependencies on eclipse.
如果没有找到 tools.jar,请尝试将其添加到您的项目对 eclipse 的依赖项中。
Firstly, copy the location of tools.jar which would look something like this C:\Program Files\Java\jdk1.x.x\lib
首先,复制 tools.jar 的位置,它看起来像这样 C:\Program Files\Java\jdk1.xx\lib
Then, on eclipse, Right click your project and go to Properties -> Java Build Path -> Libraries
然后,在 Eclipse 上,右键单击您的项目并转到 Properties -> Java Build Path -> Libraries
Click on ADD External JARsbutton.
单击添加外部 JAR按钮。
Paste the link you have copied above on File Name link bar and click OK button.
将您在上面复制的链接粘贴到文件名链接栏上,然后单击“确定”按钮。
Now, tools.jar should be listed on Libraries.
现在,tools.jar 应该列在库中。
Click okay to close the window.
单击确定关闭窗口。
Now, run the Maven install.
现在,运行 Maven 安装。
This worked for me.
这对我有用。
回答by Sofiane Majdoub
Make sure if Eclipse is pointing to a JDK and Not a JRE. For that : Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard VM and add your JDK path .
确保 Eclipse 指向的是 JDK 而不是 JRE。为此:Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard VM and add your JDK path 。
回答by Santhosh VS
When I added the JDK to the Libraries the problem was solved. The issue is like tools.jar is not found as part of the jre distribution
当我将 JDK 添加到库中时,问题就解决了。问题就像在 jre 发行版中找不到 tools.jar
回答by KiwiFlys
Make sure if Eclipse is pointing to a JDK and Not a JRE. For that : Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard VM and add your JDK path . This worked.
确保 Eclipse 指向的是 JDK 而不是 JRE。为此:Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard VM and add your JDK path 。这奏效了。
回答by nkatsar
Even after configuring Eclipse to use a JDKfrom Window -> Preferences -> Java -> Installed JRES, you may still get errors when you try to perform a Maven build.
即使在从Window -> Preferences -> Java -> Installed JRES配置 Eclipse 以使用JDK之后,当您尝试执行Maven 构建时,您仍然可能会遇到错误。
In this case make sure that the JRE tab in Maven Buildis configured correctly.
在这种情况下,请确保Maven Build中的JRE 选项卡配置正确。
Go to Run -> Run Configurations, open the Maven Buildcategory and do one of the following:
转到Run -> Run Configurations,打开Maven Build类别并执行以下操作之一:
- Make sure that the Workspace default JREis selected and it points to a JDK.
- In the Alternate JREmenu, select a configured JDK.
- 确保选择了Workspace 默认 JRE并且它指向 JDK。
- 在Alternate JRE菜单中,选择一个已配置的 JDK。