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.
Related
I have downloaded the maven 3.5.0 from here. I have set it in the path:
C:\apache-maven-3.5.0
Then i treid to add it to the path of Windows 7 as below:
Right click on my computer
Properties
Advanced System Setting
Environment Variable
New user variable and added Maven_Home with value C:\apache-maven-3.5.0
Add it to path variable with: %Maven_Home%\bin
Open cmd and ask for mvn -version in desktop
Result:
It does not recognize maven
In windows:
Download the latest version of Maven from the http://maven.apache.org/ and Navigate to Use --> Download --> Download the Binary zip archive.
1) After the download, unzip the folder and copy it to the folder. (Lets say i have copied to c:\program files\apache-maven-3.52.
2) Setting the path of Maven in environment Variables:
Search the Environment Variable --> Edit the System Environment variables--> Navigate to Advanced tab --> Environment Variables
i) MAVEN_HOME : Click New --> Variable Name : MAVEN_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
ii) M2_HOME : Click New --> Variable Name : M2_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
iii) Edit the 'Path' Environment Variable --> %M2_HOME%\bin
Testing whether Maven is installed:
mvn -version
References:-
http://www.baeldung.com/install-maven-on-windows-linux-mac
NOTE : In point iii don't forget to put semicolon(;) before and after.
Open command console
copy this
set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
cahnge the path accordingly
click enter
it's all set and now check mvn -version
I had the same problem and fixed the issue by:
Adding the M2_HOME to the USER VARIABLES
Adding the MAVEN_HOME to the USER VARIABLES
Adding the BIN folder to the PATH in the SYSTEM VARIABLES
(conform this video: https://www.youtube.com/watch?v=RfCWg5ay5B0)
Then i could run mvn -version in a NEW command terminal.
The problem get solved when i edit the path variable with ;%Maven_Home%\bin; so i should add the ; before and after it.
Adding
MAVEN_HOME variable (C:\Program Files\apache-maven-3.5.2) and M2_HOME variable (C:\Program Files\apache-maven-3.5.2\bin).
Add %MAVEN_HOME%\bin to the path in system variables .
Then mvn -version in command prompt.
Make sure you download the Binary zip file from https://maven.apache.org/download.cgi. Then it should work fine by adding it to the path variable as mentioned in other answers. I've accidentally downloaded the src.zip file and of course it didn't work.
Additionally I would add this information that worked for me
After I opened the Environment Variables and followed these steps:
System variables > path > edit > add this one: C:\apache-maven-3.6.3\bin > ok button.
Also I would send my System variables you may need
I am using Windows 10
The changes in "System variables" requires system restart to take effect. ( The same for Linux systems also)
After doing changes, you need to reopen CMD window. In my case, my terminal window was opened before updating environment variables, and changes were not reflecting there i.e. mvn -version was returning "...not recognized as an internal or external command".
1) Make sure JDK is installed, and “JAVA_HOME” variable is added as Windows environment variable.
1) Download the Maven zip file, for example : apache-maven-3.5.0-bin.zip. Unzip it to the folder you want to install Maven.
Assume you unzip to this folder – C:\Program Files\Apache\maven
3) Set the environment variables using system properties. Add M2_HOME, M2, MAVEN_OPTS to environment variables.
M2_HOME=C:\Program Files\Apache\maven\apache-maven-3.5.0
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
4) Now append M2 variable to System Path.
Append the string ;%M2% to the end of the system variable, Path.
5) Open Command Console and run this command c:\> mvn --version
you will get bellow output :
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_75\jre
Default locale: en_US, platform encoding: Cp1252
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
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!
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
When I ran mvn -version, I noticed the java_home points to ...jdk\jre (as shown below).
Is that wrong? Isn't it supposed to point to ...\jdk.x.y.z (without the \jre)?
If so, how do I reset it? (In global %java_home% points to the jdk directory)
C:\Users\Owner>mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.7.0_17
Java home: C:\Program Files\Java\jdk1.7.0_17\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
No, it's not wrong. It is pointing to the JRE used by your JDK, which is what it's supposed to. If you print out JAVA_HOME outside maven, it should print correctly:
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_07
C:\>mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
Maven home: C:\APPS\apache-maven-3.0.4\bin\..
Java version: 1.7.0_07, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_07\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
C:\>
So basically JAVA_HOME needs to point to a JDK installation (maven needs the tools.jar) but maven actually uses the jre within the JDK to run itself.
When using mvn -version, maven uses java internal java.home property, as can be seen from source code:
version.append( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) ).append( LS );
This property is not the same thing as JAVA_HOME environment setting, so it might fool you. It is actually dynamic property showing you which JRE is running your code. If you compile and execute a Test.java test class printing the same, you can see that if your JAVA_HOME points to a JDK, the value of java.home is not equal to your JAVA_HOME. This is expected.
Quoting this:
What's the difference between JAVA_HOME and java.home?
JAVA_HOME is the JDK install directory, e.g., C:\jdk5. It's meant to be
set as an environment variable and referenced in Windows batch files or
Unix scripts. I always have it in my Windows Control Panel and .tcsh
files,along with other common environment variables. Some Java
applications use the name jdk.home for this purpose, which I think is
a better name. But JAVA_HOME has been used since the beginning and is
now a convention.
java.home is the JRE install directory, e.g., C:\jdk5\jre, or
C:\Program Files\Java\jre1.5.0_06. Unlike JAVA_HOME, I never seen
java.home as an environment variable. java.home is a build-in Java
system property, whose value is the JRE install directory. Since all
Java system properties are also exposed as Ant build properties, you
can also use ${java.home} in build files.
Would jre.home be a better name? Maybe, but I don't think Sun will
change it.
You can see that maven uses JAVA_HOME on mvn.bat:
:endInit
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
..
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% ..
And if you want to make sure, you can comment out "#echo off" statement in mvn.bat, so you can see that it is being used.
TL;DR: Based on the information you've given, your configuration is correct, no need to change anything.
Edit: thanks to this thread, there was also an issue about this being confusing, which resulted in change of output for Maven version 3.5.4.
What helped me debugging mvn/jdk issues is to set this before running mvn:
set MAVEN_BATCH_ECHO=on
You get verbose output (on windows), including info how Maven picks java.