Maven打包異常Unable to locate the Javac Compiler in:Please ensure you are using JDK 1.4 or above and

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/z28126308/article/details/75635729

最近maven打包項目時出現以下異常:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.xxx: Compilation failure

Unable to locate the Javac Compiler in:
E:\JDK1.8\jdk_1.8.0_20\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.

原因:項目打包使用了以下插件,maven打包時會根據生命週期運行插件,以下插件在編譯時運行,不設置版本時默認爲2.3.2,由於個人的Java版本爲1.8的,而該插件版本2.3.2太舊所以不支持1.8,直接到http://search.maven.org搜maven-compiler-plugin把copy最新版本即可解決問題(當然也不一定需要最新的)。

當然也不排除其它原因(如環境變量,但這種情況比較小),這只是個人遇到的問題解決方法

<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章