Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven ignoring JAVA_HOME on OSX?

Tags:

java

macos

maven

For some reason Maven is ignoring JAVA_HOME on OSX.

I recently upgraded from java 8 build 11 to java 8 build 25 and removed 11 because of a bug fix in 25.

I have updated JAVA_HOME:

:~ > echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

java and javac both report the correct version:

:~ > java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

:~ > javac -version
javac 1.8.0_25

libexec is correct:

:~ > /usr/libexec/java_home 
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

the CurrentJDK symlink is correct:

:~ > ls -la /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
drwxr-xr-x  11 root  wheel   374B Nov 19 14:35 ./
drwxr-xr-x  12 root  wheel   408B Sep 23 14:29 ../
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.4@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.4.2@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.5@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.5.0@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.6@ -> CurrentJDK
lrwxr-xr-x   1 root  wheel    10B Jul 28 14:50 1.6.0@ -> CurrentJDK
drwxr-xr-x   8 root  wheel   272B Jul 29 18:41 A/
lrwxr-xr-x   1 root  wheel     1B Jul 28 14:50 Current@ -> A
lrwxr-xr-x   1 root  wheel    58B Nov 19 14:35 CurrentJDK@ -> /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents

But Maven is still trying to hit 1.8.0_11:

:~ > mvn -version
Error: JAVA_HOME is not defined correctly.
  We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/bin/java

Running OSX Mavericks.

Any idea why Maven is ignoring JAVA_HOME?

like image 755
StormeHawke Avatar asked Nov 19 '14 20:11

StormeHawke


1 Answers

A coworker told me what the problem was. He didn't want the rep points so I'm just posting the answer for anybody who may find this via google.

The solution is to put

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

in

~/.mavenrc

Apparently for whatever reason maven gets its own profile file. Creating the above file with the above value fixed the problem immediately:

:~ > mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T16:58:10-04:00)
Maven home: /usr/local/Cellar/maven/3.2.3/libexec
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
like image 164
StormeHawke Avatar answered Oct 17 '22 18:10

StormeHawke