1

Beating my head on the wall with this. Using Mac 10.10 and my java -version works but mvn -version gives me

error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java

and that's not even my correct jdk. Here is what my bash_profile looks like:export

export JAVA_HOME=/Library/Java/JavaVirtualMachine/jdk1.8.0_25.jdk/Contents/Home

export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.3
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m-Xmx512m
export PATH=$M2:$PATH
horatio1701d
  • 8,809
  • 14
  • 48
  • 77

4 Answers4

1

When I ran into this. I needed to restart the Terminal app. For it to pick up the new bash_profile changes.

user3279550
  • 108
  • 2
  • 8
0

That is (maybe) because iOS has a default Java installed and you have another Java VM that you downloaded yourself.

Try this, instead of defining the java home, let the OS use the one installed. In your profile, or on a shell script do this

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

Or whatever version of java you are using. For example, if you have java 6 and 7 installed, then running

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

will select java 7, whereas

export JAVA_HOME=`/usr/libexec/java_home -v 1.6`

will let you use Java 6.

NOTE the back ticks.

Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64
  • Thank you. That didn't work. Definitely seems like an OS conflict but I cannot track it down. A lot of posts also say to try `$(/usr/libexec/java_home)` but that didn't work either. – horatio1701d Oct 30 '14 at 00:42
  • Execute one of the commands above in Terminal.app on a command line and then execute `mvn` immediately after. If this does not work then your java installation or something else in your environment is hosed. – Steve C Oct 30 '14 at 03:53
0

Please check the mvn.sh script, make sure you have not set the JAVA_HOME in it. Or redownload a maven package and unpack.
And check /etc/launchd.conf, have you set a JAVA_HOME in it?

sanigo
  • 625
  • 4
  • 14
0

install maven in mac/linux (mac in your case), should following this http://maven.apache.org/download.cgi section:Unix-based Operating Systems (Linux, Solaris and Mac OS X)

if your default terminal is bash (echo $SHELL will output something like: /bin/bash) run echo $JAVA_HOME first before run mvn.

isaacdong-imac:~ isaac$ echo $SHELL /bin/bash 
isaacdong-imac:~ isaac$
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
isaacdong-imac:~ isaac$

if your JAVA_HOME is empty, please note this: export command ONLY current env of shell process. when you open a new shell or restart mac. export effect is gone.

see this: Set environment variables on Mac OS X Lion

Community
  • 1
  • 1
isaac
  • 13
  • 5
  • Please don't guess. There is no such file as mvn.sh – Steve C Oct 30 '14 at 02:41
  • Thank you. I do have bash and $JAVA_HOME shows my correct jdk path. But mvn -version still shows `We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java` which is not even my incorrect jdk. – horatio1701d Oct 30 '14 at 15:33
  • *export MAVEN_OPTS=-Xms256m-Xmx512m* have to be changed to *export MAVEN_OPTS="-Xms256m -Xmx512m"* – isaac Nov 03 '14 at 01:30
  • *export MAVEN_OPTS=-Xms256m-Xmx512m* have to be changed to *export MAVEN_OPTS="-Xms256m -Xmx512m"*. please show me your original .bash_profile(there is a dot before bash) content, and original shell log:commands and outputs. – isaac Nov 03 '14 at 01:37