Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)

背景:本项目使用JDK1.7

编译maven工程的时候出现如下错误:

 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)

pom中如下配置maven插件,配置中声明使用JDK1.7:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <verbose>true</verbose>
                    <fork>true</fork>
                    <executable>${JAVA_HOME}/bin/javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>

上面JAV A_HOME在%maven安装目录%/conf/settings.xml中profiles节点下新增如下;

<profile>
      <id>custom-compiler</id>
      <properties>
        <JAVA_HOME>C:\Program Files (x86)\Java\jdk1.7.0_25</JAVA_HOME>
      </properties>
    </profile>

配置后还要激活上面的配置,在settings节点下配置。

<activeProfiles>  
        <activeProfile>custom-compiler</activeProfile>  
</activeProfiles>

maven其实是有一个默认的仓库.m2仓库和默认的settings.xml配置文件,我们在这个默认的settings.xml文件中也添加了一个JAVA_HOME的变量后,编译就通过了,这就说明,maven编译的时候找的不是我在idea中配置的我自定义的settings.xml,而是先找的它默认的那个。因为里面没有,所以之前找不到JAVA_HOME,导致编译失败、

总结:maven编译的时候应该是先找的默认的settings.xml,如果找不到,才会去找我在idea的settings选项下配置的“User settings file”中配置的settings.xml文件。

解决办法:为maven默认的去找的那个settings.xml文件配置JAVA_HOME,这样自定义的文件就会生效了


参考: 
Maven构建失败 
针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值