Jenkins部署Maven項目時提示找不到JDK問題的解決方案

背景描述

今天我將一個Maven Web項目在Jenkins中配置自動構建部署時,遇到報錯:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project personal: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

一開始不明白指的什麼意思,在stackoverflow上查了一下,找到了這樣一個鏈接,雖然提問者問的是Eclipse中Maven運行的問題,但是最後面提問者的解決方案給我了一個啓發。

http://stackoverflow.com/questions/19655184/no-compiler-is-provided-in-this-environment-perhaps-you-are-running-on-a-jre-ra

具體細節和解決方案

這肯定是Maven在構建時查找JDK遇到了障礙,可能是某處環境變量配置沒有到位。我pom.xml中關於maven-compiler-plugin編譯插件的內容是這樣的:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <compilerArguments>
            <endorseddirs>${endorsed.dir}</endorseddirs>
        </compilerArguments>
    </configuration>
</plugin>

stackoverflow上的答案給我的啓發就是我這裏<configuration>中的JDK配置不明確,需要指定具體的地址:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <fork>true</fork>
        <executable>C:\Program Files\Java\jdk1.8.0_66\bin\javac.exe</executable>
    </configuration>
</plugin>

在將pom.xml修改之後,Jenkins確實構建成功了。

這個問題和我之前寫的博客使用Ant工程創建Jenkins Job時可能遇到的幾個問題中的"2. Java EE server問題"有相似之處,那邊需要明確的指明Server所在目錄,這裏也需要明確的指明JDK所在目錄。


Jenkins部署Maven項目時提示找不到JDK問題的解決方案

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