针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案

背景:本项目使用JDK1.8

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

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1

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

[html] view plain copy

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-compiler-plugin</artifactId>
  4. <version>3.1</version>
  5. <configuration>
  6. <verbose>true</verbose>
  7. <fork>true</fork>
  8. <executable>${JAVA8_HOME}/bin/javac</executable>
  9. </configuration>
  10. </plugin>

这里的${JAVA8_HOME}这个变量是在settings.xml中配置的,如下:

[html] view plain copy

  1. <profile>
  2. <id>custom-compiler</id>
  3. <properties>
  4. <JAVA8_HOME>C:\Program Files (x86)\Java\jdk1.8.0_73</JAVA8_HOME>
  5. </properties>
  6. </profile>

当然这里应该需要激活,所以settings.xml文件还应该有如下配置:

[html] view plain copy

  1. <activeProfiles>
  2. <activeProfile>custom-compiler</activeProfile>
  3. </activeProfiles>

从pom文件中CTRL点击变量JAVA8_HOME能跳到settings.xml中找到它的定义处,按理来说应该是能找到这个变量,出现上述问题并不是因为找不到这个变量。我将pom文件中的JAVA8_HOME这个变量直接用实际的路径替换,即替换为

[html] view plain copy

  1. C:\Program Files (x86)\Java\jdk1.8.0_73\bin\javac

发现编译通过,这就奇怪了。

揭晓原因:

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

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

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

时间: 2024-10-07 15:48:29

针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案的相关文章

针对maven install 报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1 解决方案

项目运行环境:jdk1.8+tomcat8 maven install 时报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1 造成此错误的原因也比较多,下面分2种情况: 情况1(常见):你可能编译在一个JRE而不是JDK上,maven 编译是要JDK的,即你的编译器配置了一个jre路径,需要换成jdk. 操作:window→preference→java→Installed JREs 点add添

Maven Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean Failed to delete access_log

I'm trying to run simple struts project using maven and tomcat. When I'm trying to exucute next goals:clean install tomcat7:run ,there is an error : [ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean)

maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang

maven打包成war时,报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang: Error assembling WAR: webxml attribute is required 原因:找不到web.xml,但是项目中明明有这个文件,在WebContent/WEB-INF/文件夹下,就是识别不了解决方法:需要在pom

解决Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project autotest_fchtgl: Compilation failure的方法

在碰到maven install 发现报错 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project autotest_fchtgl: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on

Maven错误“Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create ”解决

用maven3新建一个项目时,输入的命令如下: mvn archetype:create 出现错误如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of mojo org.apache.maven.plugins:mav

maven错误解决一:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile)

解决方法是将 jre的目录在 window->Preferences 里修改java installed里的jre目录改为jdk目录即可. 原因是在jre目录下不存在tools.jar. maven错误解决一:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile),布布扣,bubuko.com maven错误解决一:Failed to execute

Maven项目报错:Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clea

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project study-search: Failed to clean project: Failed to delete D:\Pxxtarget\tomcat\logs\access_log.2017-3-24 [ERROR] [ERROR] To see the full stac

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

使用maven打包的时候出现如下错误: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) 解决办法: 1.查看window--Preferences--Installed JREs 中是否引用的是本地的jdk,不是就改为本地jdk 2.若问题依旧存在,则还需要 查看window--Preferences--Installed JREs -- Exe

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (dist) on project hadoop-kms: An Ant BuildException has occured

编译cdh版hadoop2.5.0出现的问题 系统: CentOs66 64位 JDK:1.7 Maven: 3.0.5 Protobuf: libprotoc 2.5.0 编译命令: mvn package -DskipTests -Pdist,native **************************************************************************************** [INFO] -----------------------