匯入 maven專案出現 http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 的解決方法
阿新 • • 發佈:2019-01-28
在匯入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> - 再次進行 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,則可解決該問題。