Build error in jenkins ERROR: Maven Home /home/app/maven-2.2.1 doesn’t exist - maven

I am trying run Jenkins and Building a project.
I have install Maven 2.2.1. I downloaded Maven 2.2.1 and extracted in a folder Maven 2.2.1.
set the home path in .bash_profile.
content of .bash_profile
M2_HOME=/home/qaserver3/app/maven-2.2.1
export M2_HOME
PATH=$M2_HOME/bin:$JAVA_HOME/bin:$PATH
when I run mvn --version on terminal, I get
Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_45
Java home: /home/qaserver3/app/jdk1.6.0_45/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-358.el6.x86_64" arch: "amd64" Family: "unix"
[root#qaserver3 qaserver3]#
when I run echo $M2_HOME I get the correct home path
/home/qaserver3/app/maven-2.2.1
The above home path I have set in Jenkins.
Manage Jenkins -> Configure System -> Maven -> Maven installations ->
MAVEN_HOME = /home/qaserver3/app/maven-2.2.1
beloo I get a warining saying :
`home/qaserver3/app/maven-2.2.1 is not a directory on the Jenkins
master (but perhaps it exists on some slaves)'
but when I build the project I get this error
Console Output
ERROR: Maven Home /home/qaserver3/app/maven-2.2.1 doesn’t exist
How do I solve this issue?

Try this:
Give R/w permissions to your Jenkins user
chmod 0755 /home/qaserver3/
chmod -R 0755 /home/qaserver3/app/maven-2.2.1
Make ensure Jenkins can access all the files
sudo -iu jenkins
Run:
/home/qaserver3/app/maven-2.2.1/bin/mvn -v

You are most likely to see this warning 'home/qaserver3/app/maven-2.2.1 is not a directory on the Jenkins master (but perhaps it exists on some slaves)' when the path in your system information tab is different than you have provided in the environmental variable.
Go to manage jenkins->system information->now check the path of maven in the table.
Copy that path and paste it into the MAVEN_HOME field.
The warning should be gone by now and save it
cheers!

Related

Jenkins ERROR: Failed to parse POMs java.io.IOException: Cannot run program error=2, No such file or directory

In jenkins I am forcing the execution to happen in one of the slaves.
in jenkins configuration I have updated the JAVA_HOME and MAVEN location to the location where its installed in the slave. When I start the build in jenkins I receive the following error
ERROR: Failed to parse POMs
java.io.IOException: Cannot run program "/home/jmeter/jdk1.8.0_112/bin/java" (in directory "/home/jmeter/apache-jmeter-2.13/bin/workspace/MyProject"): error=2, No such file or directory
PS : /home/jmeter/apache-jmeter-2.13/bin/workspace/MyProject - This directory got created and does exist in the slave machine
Can someone please share their expertise in resolving it ?
I needed to add Tool location of JDK8 for machine i run test on.
looks like there is a problem in the MVN installation. PLS make sure in the global config that you have the required mvn installation.
jenkins-->manage-->configure look for Maven installations and use automatic installation for the required version
make sure you have the JDK installation in the same config file
After wasting one day trying with different things going through different suggestions I got nothing. But, it was actually very simple. Please add the JDK path as bellow to your JDK Path in Jenkins-
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
You should assign the JDK in the Meta Data,The JAVA_HOME of system is not work for build.
Check your Maven version selected into the Manage Jenkins->Global Configurations->Maven->Maven Installations->Install from Apache->Version is same as installed on the server and your maven project.
You might have left out a few dependencies resulting in this issue.
Go back and download java and set the path as before:
To download, use
$yum -y install java-1.8*
Set the path to
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.amzn2.0.1.x86_64
Note: Get your path using command
find /usr/lib/jvm/java-1.8* | head -n 3
This got resolved after adding maven_home and providing the path in the global properties.
Go to: Jenkins ⟶ Manage Jenkins ⟶ Global Properties ⟶ MAVEN_HOME [C:\Program Files\Apache\apache-maven-3.6.3-bin\apache-maven-3.6.3]
Just in case someone else runs into this. I was getting this error because someone setup the JDK in Global Tool Configuration to download a windows version of the JDK, but my instance of jenkins is running on linux. Once I made the change to use a linux version of the JDK my issue was resolved.

MAVEN - Setting Path in Redhat so the maven commands can be run from anywhere

I have just installed Maven on Redhat, the apache-maven-3.3.9 is located in /root/, I ran the following command to set the path (JDK java home path already set and when I type $PATH the below path does show, along with when I type mvn --version):
export PATH=/root/apache-maven-3.3.9/bin:$PATH
The project I want to build with Maven is also in /root/ however, I cannot use the maven commands within the project or anywhere else except for /apache-maven-3.3.9/bin directory.
Any help would be much appreciated!
You need to add it to your ~/.profile file.
export PATH=$PATH:/root/apache-maven-3.3.9/bin
so that when you exit the terminal and start a new terminal instance path is not lost

Hudson ERROR: M2_HOME is set to an invalid directory

I am using a computer with Windows 7, and I have Hudson installed on it. I have had this installation for a while, and it has been working fine up till now.
Something has changed. Now, whenever I try to build a project, after successfully checking out the project from SVN, it fails with this message:
ERROR: M2_HOME is set to an invalid directory.
M2_HOME = "C:\Build\Hudson\.hudson\jobs\Score_Plugin\workspace\.."
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
I cannot figure out why it is giving me this error. Why is Hudson trying to find M2_HOME in its own workspace? I tried the following, which seems to say that my Maven installation in my environment is just fine:
1. I opened up a CMD and typed in `where mvn` and got the following:
C:\Build\Maven\apache-maven-3.0.5\bin\mvn
C:\Build\Maven\apache-maven-3.0.5\bin\mvn
2. I typed in `mvn -version` and got this:
Apache Maven 3.0.5 <r01de14724cdef164cd33c7c82fe155faf9602da; 2013-02-19 05:51:28-0800>
Maven home: C:\Build\Maven\apache-maven-3.0.5
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Build\Java\jdk1.7.0_25_x64\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
3. I checked to see, and I have a `MAVEN_HOME` environment variable set to `C:\Build\Maven\apache-maven-3.0.5`.I also have `%MAVEN_HOME%\bin` in my path.
It looks like my environment is working.
4. In an attempt to solve this error, I created a M2_HOME environment variable and set it equal to %MAVEN_HOME%.
5. To top it all off, I've rebooted my machine.
I'm still getting this error. I'm getting it for every project I try to build in Hudson. I'm not sure what I else I can do. Any ideas?
My understanding is that %M2_HOME% is the home of the local Maven repository as opposed to %MAVEN_HOME% which is the Maven installation directory.
From memory, I think the local Maven repository on Windows is in C:\Documents and Settings\User\.m2\ but I've been Linux through-and-through for a few years now so I may be wrong.
Check for this local repository folder and try setting the variable to there instead.
I am not sure why this worked, but it did.
As suggested by sbk's comment, I went to the build configuration. I clicked "advanced" to look for the `Use private Maven repository` option.
I expected to see this option selected as it would explain the problem. But it wasn't. I didn't expect it would help, but I selected the option anyway just to see what would happen:
Amazingly, it worked! My project builds again in Hudson. I still don't know what caused this problem in the first place, or why this fixed it, but since it did this is the answer for me unless someone else can explain why this worked.
I was getting same error. Earlier my directory was C:\apache-maven-3.0.4\apache-maven-3.0.4\bin
I renamed the folder structure as C:\maven\apache-maven-3.0.4\bin
Also updated the system variable accordingly

Jenkins executing maven from incorrect path

This happens for both: maven projects, and freestyle projects, when maven target is envoked, it tries to execute mvn using absolute path.
[MY-Job] $ tools/Maven/Jenkins_Private_Maven/bin/mvn -f cc/pom.xml -Ddeploy_env=xxx.dev.prv -Dbranch=dev -D-Dsmdist.target=/opt/builds -U clean test -DtestGroups=unit,delegate -Do verride:server=xxx.dev.prv
FATAL: command execution failed
java.io.IOException: Cannot run program "tools/Maven/Jenkins_Private_Maven/bin/mvn" (in directory "workspace/MY-Job"): java.io.IOException: error=2, No such file or directory
I can see that mvn is installed at user's home :
/home/jenkins/tools/Maven/Jenkins_Private_Maven/bin/mvn
but it's trying to run it from the workspace:
/home/jenkins/workspace/MY-Job/tools/Maven/Jenkins_Private_Maven/bin/mvn
Add the default maven installation under (Jenkins -> configuration)
Goto the failing job and make sure you choose the default maven installation from dropdown
Run the job. Success!
Are you sure you have set up Maven in Jenkins -> configuration like this
I have hunch you have a accidental **"."** current directory reference somewhere in your maven set up.
This looks like an auto installed Maven by Jenkins. In which case the previous answers are not correct.
It would seem in this occasion that you have not specified a "remote fs root" for your slave in the salve setup - later versions of Jenkins flag not setting this up correctly as an error.
in Jenkins 2.43:
Manage Jenkins -> Global Tool Configuration -> Maven

Maven home (M2_HOME) not being picked up by IntelliJ IDEA

I am trying to do a simple maven build with IntelliJ IDEA 10.5.1 on OS X Lion and am getting the following error:
Error running my-app [package]: No valid Maven installation found.
Either set the home directory in the configuration dialog or set the
M2_HOME environment variable on your system.
I have set M2_HOME to the following, but I am still having issues. And yes, I did restart IntelliJ.
$ echo $M2_HOME
/usr/share/maven
I then manually entered the path to maven in IntelliJ's Maven Settings for the project. This is not something that I want to do for every project, so is there something I am missing with how to get IntelliJ know where my maven home is?
type in Terminal:
$ mvn --version
then get following result:
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 16:51:28+0300)
Maven home: /opt/local/share/java/maven3
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: ru_RU, platform encoding: MacCyrillic
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"
here in second line we have:
Maven home: /opt/local/share/java/maven3
type this path into field on configuration dialog. That's all to fix!
Mac OS apps cannot read bash environment variables. Look at this question Setting environment variables in OS X? to expose M2_HOME to all applications including IntelliJ. You do need to restart after doing this.
Another option is to add the M2_HOME variable at: IntelliJ IDEA=>Preferences=>IDE Settings=>Path Variables
After a restart of IntelliJ, IntelliJ IDEA=>Preferences=>Project Settings=>Maven=>Maven home directory should be set to your M2_HOME variable.
Got to this answer ? probably the answers above are to long ...
just type in :
echo "setenv M2_HOME $M2_HOME" | sudo tee -a /etc/launchd.conf
and restart your mac (thats it!)
restarting is annoying ? just use the command :
grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
and restart IntelliJ IDEA
If M2_HOME is configured to point to the Maven home directory then:
Go to File -> Settings
Search for Maven
Select Runner
Insert in the field VM Options the following string:
Dmaven.multiModuleProjectDirectory=$M2_HOME
Click Apply and OK
In case you don't want to use the M2_HOME and want to direct the IntelliJ to the maven installation you can simply set it by:
goto File => Setting => Maven => Maven home directory
point to your maven build directory e.g. /usr/local/maven/apache-maven-3.0.4
A better way is to have a symlink e.g. 'latest' for the latest version and point your IntelliJ to use that for consistency, given latest points to the latest version of maven installed on your box.
If you are having this problem with a homebrew installation of maven 3 on the OSX 10.9.4 then check out this blog post.

Resources