After Installing Java JDK 7 For Mac OS X - mvn -version still shows java version 1.6.0_31
Solution 1
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
Solution 2
The problem is that the symbolic link "CurrentJDK" inside the versions of JavaVm.framework points to the old jdk, so when i used the following commands to set the CurrentJDK to the latest one (1.7.0_45) it works
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents CurrentJDK
reference: http://java.dzone.com/articles/installing-jdk-7-mac-os-x
Solution 3
To find the path from Java Preferences, try
/usr/libexec/java_home -X
My Java7 entry looks like this:
<dict>
<key>JVMArch</key>
<string>x86_64</string>
<key>JVMBundleID</key>
<string>com.oracle.java.7u04.jdk</string>
<key>JVMEnabled</key>
<true/>
<key>JVMHomePath</key>
<string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
<key>JVMIsBuiltIn</key>
<false/>
<key>JVMName</key>
<string>Java SE 7</string>
<key>JVMPlatformVersion</key>
<string>1.7</string>
<key>JVMVendor</key>
<string>Oracle Corporation</string>
<key>JVMVersion</key>
<string>1.7.0_04</string>
</dict>
Solution 4
You need to change the JAVA_HOME
environment variable to the new JDK 1.7 location.
Look at this question for possible locations where JAVA_HOME might be defined. In a terminal, type which java
to find the path of your Java installation, and then update JAVA_HOME
to point to that path (but exclude the trailing bin folder).
Solution 5
In case anyone is installing Maven on a 64-bit Mac running Mac OSX 'Mavericks' save yourself some time and some hair pulling trying to get Maven installed. I was trying to follow this (which failed because the location of the java_home has changed on Mavericks:
http://maven.apache.org/download.cgi
I was pulling my hair out until I found this website, which recommends you Install homebrew and follow the instructions on this page: http://techspunky.blogspot.in/2013/10/how-to-install-maven-on-mac-osx-109.html
once complete don't panic when $ maven -version doesn't work, instead use $mvn --version as maven.apache.org/download.cgi recommended.
It worked, but then I noticed the Java SDK Maven was using was Java version: 1.6.0_65, which is not the latest SDK I installed on the system.
Once I set the JAVA_HOME=/usr/libexec/java_home
It was using the correct SDK: Maven home: /usr/local/Cellar/maven/3.1.1/libexec Java version: 1.7.0_45, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
Success! but wait... next time I opened the terminal and ran mvn -v it went back to java version 1.6. WTH!
its some sort of supposed bug from what I read use:
echo JAVA_HOME=/usr/libexec/java_home -v 1.7
| sudo tee -a /etc/mavenrc
and now:
Maven home: /usr/local/Cellar/maven/3.1.1/libexec Java version: 1.7.0_45, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
Bruce Phillips
Updated on November 03, 2020Comments
-
Bruce Phillips over 3 years
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.
-
Bruce Phillips about 12 yearsAre you sure I need to that on a Mac OS X? I've not had to do that in the past. If I do need to set JAVA_HOME how do I know what path to use as the install of Java JDK 7 did not give me any install path information and the Java Preference utility app on the Mac doesn't show a path to the JDK 1.7
-
Nate about 12 yearsIf you look at your question above, you can see that JAVA_HOME has already been defined and currently points to the old 1.6 JDK. I'm not familiar with how to change environment variables in OSX, but this is what Maven uses by default.
-
Bruce Phillips about 12 yearsThe problem is that an Apple update normally updates the java version and sets the JAVA_HOME value. Setting the JAVA_HOME value in .bashrc doesn't work on OS X as it does in linux. Also no where can I find the path to the JDK 7 installed by Oracle.
-
Bruce Phillips about 12 yearsAlso Nate my question is NOT a duplicate of the post you linked to. I'm on OS X and have updated to Java JDK 7 using Oracle install for Mac OS X, which was just released on April 26.
-
peter_budo about 12 yearsNo Mac instead of .bashrc uses .bash_profile and you should be able to find instalation under /System/Library/Java/JavaVirtualMachines/ where you need to point on your new 1.7.0 Java version
-
Bruce Phillips about 12 yearsPeter - there is only 1 JDK listed under that directory and it is not the new JDK 1.7. siteamnotebook1-2:~ bphillips$ cd /System/Library/Java/JavaVirtualMachines/ siteamnotebook1-2:JavaVirtualMachines bphillips$ ls -l total 0 drwxr-xr-x 3 root wheel 102 Nov 1 12:49 1.6.0.jdk
-
Bruce Phillips about 12 yearsNate - using which java in a terminal just returns /usr/bin/java and that is not the path to the JDK 1.7
-
Dean Hiller almost 12 yearsgrrrrr, I did that and the path it lists for my jdk1.7 does not exist at all :(
-
amod over 11 yearsI recently installed Java 6 and I am not able to locate JavaPreferences.app bcz mac now does not provide support for Java. Can tell me now how can I set my jvm without using JavaPreferences.
-
Ibolit over 11 yearsYou can accept your own answer. That will show all the rest of us that this solved this problem. And you will have 10 more ponts :)
-
skytteren over 11 yearsI added to ~/.bash_profile: export JAVA_HOME=$(/usr/libexec/java_home)
-
cdeszaq over 10 years
export JAVA_HOME=`/usr/libexec/java_home`
worked well for me to get the JAVA_HOME var exported correctly. -
ndequeker about 10 yearsmake sure you specify the right version for
jdk1.7.0_45.jdk
, mine wasjdk1.7.0_51.jdk
-
Ivan Voroshilin over 9 yearsI wonder why Oracle developers didn't do it automatically? It's not trivial for me. This answer saved my day.
-
mac almost 9 yearsOr you can do "export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)" in one shot instead of changing using Java Preferences.app
-
Wolf7176 almost 8 yearsthis is not working for me. I am on el captian. the mvn java version refuses to change. JAVA_HOME is accurate
-
Wolf7176 almost 8 yearsunable to open the Java Preferences App in El Captian, I went from System Preferences - > Java.
-
absmiths over 3 yearsFor me the culprit was /etc/mavenrc. It was hardcoded to 1.8 when I needed 12.