Java 无法在项目上执行目标 org.apache.maven.plugins:maven-compiler-plugin (default-compile): Fatal error compiling: tools.jar not found

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29700576/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:28:29  来源:igfitidea点击:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin (default-compile) on project: Fatal error compiling: tools.jar not found

javaeclipsemaventomcatjakarta-ee

提问by abdul khan

I have done all the steps provided in http://www.tutorialspoint.com/jsf/jsf_environment_setup.htm

我已经完成了http://www.tutorialspoint.com/jsf/jsf_environment_setup.htm 中提供的所有步骤

Apache Maven and Apache tomcat both are ready. I also set the environments. I created Maven project in Eclipse, it gives Build Failure while I run this using Maven build.

Apache Maven 和 Apache tomcat 都已准备就绪。我还设置了环境。我在 Eclipse 中创建了 Maven 项目,当我使用 Maven 构建运行它时它给出了构建失败。

It gives this error

它给出了这个错误

"Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project Hello2: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre1.8.0_40..\lib\tools.jar"

“无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project Hello2: Fatal error compiler not found: tools.jar not found: C:\Program Files\Java \jre1.8.0_40..\lib\tools.jar"

What should I do?

我该怎么办?

采纳答案by Shane Voisard

You need to set eclipse's default installed "jre" to a jdk. Eclipse Window Menu => Preferences => enter search string "jre" in left navigation pane => click on "Installed JREs" in left navigation pane => Click Add and browse to your JDK. => click the check box next to the JDK to make it default.

您需要将 eclipse 的默认安装“jre”设置为 jdk。Eclipse 窗口菜单 => 首选项 => 在左侧导航窗格中输入搜索字符串“jre” => 在左侧导航窗格中单击“已安装的 JRE” => 单击添加并浏览到您的 JDK。=> 单击 JDK 旁边的复选框以将其设为默认值。

You may need to download and install the java jdk if you don't already have it.

如果您还没有 java jdk,则可能需要下载并安装它。

Also ensure the eclipse run configuration is set to use the default jdk you set up: Run Menu => Run Configurations => Select the run config for your project (Maven Build) => Click JRE tab => Under Runtime JRE select "workspace default".

还要确保将 eclipse 运行配置设置为使用您设置的默认 jdk:运行菜单 => 运行配置 => 为您的项目选择运行配置(Maven 构建)=> 单击 JRE 选项卡 => 在 Runtime JRE 下选择“workspace default ”。

回答by Kun

I delete my .m2 local local repository and re-run it. It works.

我删除了我的 .m2 本地本地存储库并重新运行它。有用。

回答by Vinayak Dornala

Check the JAVA version, It should be same across all the places. See screenshots.

检查JAVA版本,它应该在所有地方都一样。见截图。

  1. pom.xml enter image description here
  2. JAVA build path enter image description here
  3. JAVA compiler enter image description here
  1. pom.xml 在此处输入图片说明
  2. JAVA构建路径 在此处输入图片说明
  3. JAVA编译器 在此处输入图片说明

Note: To see configuration window for 2 and 3... right click on the project and click properties

注意:要查看 2 和 3 的配置窗口...右键单击项目并单击属性

回答by ASHISH KARN

I am using windows OS with JDK 1.9 in eclipse Oxygen. I faced this issue while compiling the project with JDK 1.9 while using maven. Changing from set "JAVACMD=C:\Program Files\Java\jdk-9.0.1\bin\java.exe" to set "JAVACMD=C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" of mvn.cmd file present in C:\apache-maven-3.5.2\bin solved the issue. Also, make sure the compiler you use to build the project is correctly configured in IDE you use.

我在 eclipse Oxygen 中使用带有 JDK 1.9 的 Windows 操作系统。我在使用 maven 时用 JDK 1.9 编译项目时遇到了这个问题。从设置“JAVACMD=C:\Program Files\Java\jdk-9.0.1\bin\java.exe”更改为设置“JAVACMD=C:\Program Files\Java\jdk1.8.0_91\bin\java.exe”存在于 C:\apache-maven-3.5.2\bin 中的 mvn.cmd 文件解决了该问题。此外,请确保在您使用的 IDE 中正确配置了用于构建项目的编译器。