jenkins構建java項目找不到命令mvn,java的解決方案

來源:互聯網
上載者:User

標籤:工具   plugin   init   run   task   ati   技術分享   start   技術   

jenkins構建java項目時出現的報錯情況:

$ mvn clean installFATAL: command execution failedjava.io.IOException: error=2, No such file or directoryat java.lang.UNIXProcess.forkAndExec(Native Method)at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)at java.lang.ProcessImpl.start(ProcessImpl.java:134)at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)Caused: java.io.IOException: Cannot run program "mvn" (in directory "/var/lib/jenkins/workspace/es"): error=2, No such file or directory



報錯情況2:

/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven_3.5.3/bin/mvn clean installwhich: no java in (/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven_3.5.3/bin:/sbin:/usr/sbin:/bin:/usr/bin)The JAVA_HOME environment variable is not defined correctlyThis environment variable is needed to run this programNB: JAVA_HOME should point to a JDK not a JREBuild step ‘Invoke top-level Maven targets‘ marked build as failureFinished: FAILURE


報錯情況3:

[INFO] Changes detected - recompiling the module![INFO] Compiling 33 source files to /var/lib/jenkins/workspace/es/target/classes[INFO] -------------------------------------------------------------[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?[INFO] 1 error[INFO] -------------------------------------------------------------[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 02:42 min[INFO] Finished at: 2018-05-29T18:32:22+08:00[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project ruhnn-visual-search-background: Compilation failure[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?[ERROR] [ERROR] -> [Help 1][ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException


解決方案:

安裝maven  並配置到jenkins配置裡  https://maven.apache.org/download.cgiwget  http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gztar zxvf apache-maven-3.5.2-bin.tar.gzmv apache-maven-3.5.2 /usr/local//usr/loca/apache-maven-3.5.2/bin/mvn --versionjenkins -> 系統管理 -> 全域工具配置Maven Configuration -> Settings file in filesystem -> File Path /usr/local/apache-maven-3.5.2/conf/settings.xmlGlobal settings file on filesystem -> File Path 同上下拉到Maven,Maven安裝,Name(自訂,如maven3.5.2),MAVEN_HOME填 “/usr/local/apache-maven-3.5.2”左下角“save”

安裝maven 也可以參考:http://www.cnblogs.com/weifeng1463/p/8920765.html

 

 

安裝jdk jenkins -> 系統管理 -> 全域工具配置JDK安裝JDK  別名  JDK1.8 自動安裝          從java.sun.com 安裝          版本  Java SE Development Kit 8u162  

 


 


最後測試可以成功構建:


 


jenkins構建java項目找不到命令mvn,java的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.