Java 在 Jenkins 中找不到 Maven
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45777031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven not found in Jenkins
提问by Charo
I am running my Maven/Spring project in Jenkins (just testing it out, first time) using the shell script option with:
我正在 Jenkins 中运行我的 Maven/Spring 项目(只是测试它,第一次)使用 shell 脚本选项:
mvn spring-boot:run
mvn spring-boot:run
I get the build error:
/Users/Shared/Jenkins/tmp/jenkins8087926087546049217.sh: line 2: mvn: command not found
我收到构建错误:
/Users/Shared/Jenkins/tmp/jenkins8087926087546049217.sh: line 2: mvn: command not found
How can I fix this? Its a Spring-boot app. It works fine when I run mvn spring-boot:run
via command line.
我怎样才能解决这个问题?它是一个 Spring-boot 应用程序。当我mvn spring-boot:run
通过命令行运行时它工作正常。
采纳答案by Anil Kumar Athuluri
回答by JinWeiMin
makesure you maven config is true. you can use cmdand run:
确保您的 Maven 配置为 true。您可以使用cmd并运行:
mvn -version
if no error, try
如果没有错误,请尝试
mvn spring-boot:run
回答by Bor Is
I had a similar problem on windows. Maven worked fine from console, but failed when called as cmd command from Jenkins.
我在 Windows 上遇到了类似的问题。Maven 从控制台运行良好,但在 Jenkins 中作为 cmd 命令调用时失败。
The reason is that Jenkins is installed and run as a ?system user‘ service. This means the process can‘t see the ENV variables and PATH of your user (user level). Setting up maven in PATH and ENV variables on system level makes the trick.
原因是 Jenkins 作为“系统用户”服务安装和运行。这意味着该进程无法看到您的用户(用户级别)的 ENV 变量和 PATH。在系统级别的 PATH 和 ENV 变量中设置 maven 是诀窍。
P.S.: @Charo the maven config moved from Configure System to Global Tool Configuratin in newer Jenkins versions
PS:@Charo 在较新的 Jenkins 版本中,maven 配置从配置系统移动到全局工具配置
回答by rakesh
I had faced the similar issue where I have put the Name As maven-3.3.9
我遇到了类似的问题,我将名称设置为 maven-3.3.9
And Placed the MAVEN_HOME LIKE : E:\Softwares\apache-maven-3.3.9\bin
并放置了 MAVEN_HOME LIKE : E:\Softwares\apache-maven-3.3.9\bin
回答by LIU YUE
回答by mushroom_lb
export MAVEN_HOME=/opt/maven
export PATH=$PATH:$MAVEN_HOME/bin
mvn --version
mvn clean package
and then mvn install
然后 mvn 安装
回答by Suneet Khurana
I have faced this issue in my ubuntu 16.04 machine and the actual reason is the maven bin directory path is not set $PATH variable.
我在 ubuntu 16.04 机器上遇到过这个问题,实际原因是 maven bin 目录路径没有设置 $PATH 变量。
How to check?
如何检查?
you can append below lines in execute shell prompt of Jenkins GUI.
echo $M2_HOME echo $PATH mvn clean install
When you will build again then you will see M2_HOME or maven bin path is not set in $PATH variable.
Or you can log in in to Jenkins user from the root and run following commands.
su - Jenkins echo $PATH
您可以在 Jenkins GUI 的执行 shell 提示中附加以下几行。
echo $M2_HOME echo $PATH mvn clean install
当您再次构建时,您将看到 M2_HOME 或 maven bin 路径未在 $PATH 变量中设置。
或者您可以从 root 登录到 Jenkins 用户并运行以下命令。
su - Jenkins echo $PATH
Solution::
解决方案::
1. logged in to root user.
2. then this command cd /etc/profile.d/
3. vim maven.sh then add below lines
export M2_HOME=/usr/local/maven
export PATH=$PATH:$M2_HOME/bin
4. run this command chmod +x maven.sh
5. then login to jenkins user (su - jenkins) then see again maven path is set or not via (echo $PATH) command.
6. If the path is set then restart Jenkins service
service jenkins restart
and re-login in Jenkin GUI (http://localhost:8080/)
7. Now rebuild your job then you will get success :-)