Maven ignores JAVA_HOME on OSX?

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 due to a 25 error.

I updated JAVA_HOME :

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

java and javac reporting 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 correct:

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

The currentJDK symbolic link 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 

Launch OSX Mavericks.

Any idea why Maven is ignoring JAVA_HOME ?

+8
java maven macos
source share
2 answers

An employee told me what the problem is. He didn’t want the replica points, so I just send the answer to everyone who can find this through google.

The solution is to put

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

in

 ~/.mavenrc 

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

 :~ > 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" 
+21
source share

I fixed this problem by adding

export JAVA_HOME="$(/usr/libexec/java_home)"

to

~/.mavenrc

Apple recommends using /usr/libexec/java_home instead of using the entire Java path

+2
source share

All Articles