导入 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在这里插入图片描述
再次进行 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,则可解决该问题。

本文章转载于:https://blog.csdn.net/ZkD953/article/details/79935520

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值