1. 程式人生 > >匯入 maven專案出現 http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 的解決方法

匯入 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 版本,具體解決方法如下:

  1. window —>preferences—>Java—>Installed JREs 
  2. 找到 JDK 的安裝路徑
  3. 選擇 JDK —>apply
  4. 再次進行 maven clean,maven install,如果仍然存在該問題,進行 一下操作:
  5. 開啟 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
  6. 再次進行 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):

    1. <profiles>
    2.        <profile>
    3.             <id>jdk-1.8</id
      >
    4.             <activation>
    5.                 <activeByDefault>true</activeByDefault>
    6.                 <jdk>1.8</jdk>
    7.             </activation>
    8.             <properties>
    9.                 <maven.compiler.source>1.8</maven.compiler.source>
    10.                 <maven.compiler.target>1.8</maven.compiler.target>
    11.                 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    12.             </properties>
    13.     </profile>
    14. </profiles>

    再次重新Maven > Update project,則可解決該問題。