maven package 打包報錯 Failed to execute goal
阿新 • • 發佈:2019-01-05
總結一下maven 打包,專案工程開發工具idea14,使用 JDK 1.8 版本
1.打包前需要先將idea關掉,不然會導致mvn clean的時候,部分檔案刪除不掉,mvn package的時候,也會丟失檔案。
2.mvn package打包報錯:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.6.1:clean (default-clean) on project
解決辦法:
1. pom中如下配置maven外掛,配置中宣告使用JDK1.8:
<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>
這邊的${JAVA8_HOME}可能獲取不了,可以直接寫路徑:
${JAVA8_HOME}這個變數是在settings.xml中配置的,如下:
<profile> <id>custom-compiler</id> <properties> <JAVA8_HOME>C:\Program Files (x86)\Java\jdk1.8.0_73</JAVA8_HOME> </properties> </profile>
當然這裡應該需要啟用,所以settings.xml檔案還應該有如下配置:
<activeProfiles>
<activeProfile>custom-compiler</activeProfile>
</activeProfiles>
揭曉原因:
idea本身可以編譯通過的原因是:maven其實是有一個預設的倉庫.m2倉庫和預設的settings.xml配置檔案,這個預設的settings.xml檔案中也添加了一個JAVA_HOME的變數後,編譯就通過了。而在用cmd視窗mvn package命令打包,報編譯失敗,這就說明,maven編譯的時候找的不是我在idea中配置的settings.xml,而是找的我原來配置E:\Tools\Maven\conf下的settings.xml。因為裡面沒有預設配置編譯使用1.8版本的jdk,所以之前找不到JAVA_HOME,導致編譯失敗。