码迷,mamicode.com
首页 > 编程语言 > 详细

jenkins构建java项目找不到命令mvn,java的解决方法

时间:2018-05-30 10:49:15      阅读:1362      评论:0      收藏:0      [点我收藏+]

标签:工具   plugin   init   run   task   ati   技术分享   start   技术   

jenkins构建java项目时出现的报错情况:

$ mvn clean install
FATAL: command execution failed
java.io.IOException: error=2, No such file or directory
	at 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 install
which: 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 correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Build step ‘Invoke top-level Maven targets‘ marked build as failure
Finished: 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.cgi
wget  http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz
tar zxvf apache-maven-3.5.2-bin.tar.gz
mv apache-maven-3.5.2 /usr/local/
/usr/loca/apache-maven-3.5.2/bin/mvn --version
jenkins -> 系统管理 -> 全局工具配置
Maven Configuration -> Settings file in filesystem -> File Path /usr/local/apache-maven-3.5.2/conf/settings.xml
Global 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的解决方法

标签:工具   plugin   init   run   task   ati   技术分享   start   技术   

原文地址:https://www.cnblogs.com/weifeng1463/p/9109317.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!