After Installing Java JDK 7 For Mac OS X - mvn -version still shows java version 1.6.0_31

Bruce Phillips picture Bruce Phillips · Apr 26, 2012 · Viewed 94.4k times · Source

Oracle released Java JDK 7 on April 26 for Mac OS X. I followed the install instructions and when I do java -version in a terminal window I get:

java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

However when I do mvn -version in the terminal window I get:

Apache Maven 3.0.2 (r1056850; 2011-01-08 18:58:10-0600)
Java version: 1.6.0_31, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.3", arch: "x86_64", family: "mac"

How can I get Maven to use the Java JDK 1.7.0_04?

Thanks for the help.

Answer

Bruce Phillips picture Bruce Phillips · Apr 28, 2012

Finally found the answer here:

http://www.adam-bien.com/roller/abien/entry/java_se_development_kit_7

You should use JAVA_HOME=$(/usr/libexec/java_home) instead on a Mac and then set the current jdk via "Java Preferences.app".

Set JAVA_HOME in ~/.profile