导入 maven项目出现 http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 的解决方法
在导入maven 项目,进行 maven clean,maven install 时 出现如下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mvc2: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
主要是由于 JDK 的版本问题,running on a JRE rather than a JDK ,我们要将 JRE 换成 JDK 版本,具体解决方法如下:
- window —>preferences—>Java—>Installed JREs
- 找到 JDK 的安装路径
- 选择 JDK —>apply
- 再次进行 maven clean,maven install,如果仍然存在该问题,进行 一下操作:
- 打开 pom.xml 文件,在plugins 下 进行如下配置 将 source target 改成 与 JDK 对应版本 (我是1.8):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
将 jdk 版本设置为 1.8 -
再次进行 maven clean,maven install,不再报错,能加载完成, 但项目 左上角 仍可能 小红叉,具体错误如下:
Dynamic Web Module 3.0 requires Java 1.6 or newer.。具体解决方法如下:
找到 apache-maven 的安装路径;
在 apache-maven-3.5.3/conf/settings.xml文件中加入如下配置(取决于JDK 版本,我的是 1.8):- <profiles>
- <profile>
- <id>jdk-1.8</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- <jdk>1.8</jdk>
- </activation>
- <properties>
- <maven.compiler.source>1.8</maven.compiler.source>
- <maven.compiler.target>1.8</maven.compiler.target>
- <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
- </properties>
- </profile>
- </profiles>
再次重新Maven > Update project,则可解决该问题。