mvn command not working on mac OS X Yosemite
21,739
export PATH=$M2:$PATH
should be export PATH=$M2/bin:$PATH
or export PATH=$M2_HOME/bin:$PATH
Also JAVA_HOME should be something like this
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60
then
export PATH=$JAVA_HOME/bin:$PATH
That's all.
All in one
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH
Author by
John
Updated on August 04, 2022Comments
-
John almost 2 years
I have performed all the necessary steps like the following after referring other Stack overflow threads and online resources for installing / configuring maven. Here is what I did :
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9 export M2=$M2_HOME/bin
My Java Home variable is also, set, as shown below:
echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home export PATH=$M2:$PATH
Inspite of doing all of the above, when I run
mvn --version
, I getError: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home/bin/java
.PATH Output is as follows :
echo $PATH /usr/local/apache-maven/apache-maven-3.3.9/bin:/usr/local/apache-maven/apache-maven-3.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/MacGPG2/bin
-
javapapo over 8 years
-
John over 8 years@11thdimension Thanks for the answer and comment javapapo. My path variable is
echo $PATH /usr/local/apache-maven/apache-maven-3.3.9/bin:/usr/local/apache-maven/apache-maven-3.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/MacGPG2/bin
I made the changes inJAVA_HOME
variable as suggested. Still, I need to runsudo mvn --version
to make sure that maven is running properly. If I just runmvn --version
withoutsudo
, I get the errorError: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_60/bin/java
-
John over 8 yearsCould anyone explain me why it throws
JAVA_HOME
error in spite of setting the path correctly? -
11thdimension over 8 yearsAre you able to use Java commad in the terminal ? If you are able to use it, then try to run
which java
, which will give you the correct path to java executable. Post the output if you can find the path. -
John over 8 years@11thdimension When I ran the following command on the terminal:
ls -l
which java``, I got the following :` lrwxr-xr-x 1 root wheel 74 Jun 25 2015 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java` -
11thdimension over 8 yearswhat is the content of
/Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home
directory ?