Maven 專案編譯時報錯:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1 ...
pom.xml 中配置了 maven-compiler-plugin 並引用 ${JAVA8_HOME} 變數指定 javac 路徑:
<profile>
<id>custom-compiler</id>
<properties>
<JAVA8_HOME>C:\Program Files (x86)\Java\jdk1.8.0_73</JAVA8_HOME>
</properties>
</profile>
<activeProfiles>
<activeProfile>custom-compiler</activeProfile>
</activeProfiles>
settings.xml (例如專案目錄下或自訂路徑)。${maven.home}/conf/settings.xml (安裝目錄) 或 ${user.home}/.m2/settings.xml (用戶目錄)。settings.xml 中**缺少對應 Profile 或未啟用**,${JAVA8_HOME} 解析為空字串,導致 executable 路徑無效,編譯失敗。${JAVA8_HOME} 直接替換為絕對路徑即可編譯通過,證實是變數解析失敗。# Windows rename %MAVEN_HOME%\conf\settings.xml settings.xml.bak # Linux/Mac mv $MAVEN_HOME/conf/settings.xml $MAVEN_HOME/conf/settings.xml.bak
強制 Maven 讀取用戶目錄 ~/.m2/settings.xml 或 IDE 指定的自訂設定檔。
C:/Program Files/Java/jdk1.8.0_73/bin/javac true
缺點:專案遷移需修改路徑,不利團隊協作。