MacOS X Mountain Lion and Java 7 installation
Today I set out to get Java 7 JDK running on MacOS X Mountain Lion (10.8.2). As Apple actually only installs Java 6 (1.6.x) one needs to get Java 7 from the Oracle website at the Java SE download site.
Once downloaded simply run the installer and it (should) install Java 7 properly on your system. After that, you can use the following command to make Java 7 the active version to use:
[code]/usr/libexec/java_home -v 1.7.0_11 –exec javac -version[/code]
Now, if you use “java -version” it should actually give the output that it used Java 7.
Now the above should all be according to the book, but as things are when it comes to Java they are never “click and go”. One of the problems, I’ve had was that no application on the terminal actually picked up the Java 7 JDK. Digging around a bit showed me that the installation created sym links in the “/System/Library/Frameworks/JavaVM.framework/Versions/” directory.
As it turns out the “CurrentJDK” linked to the “old” Java 6 (1.6) installation. So, in order to point it to Java 7 I’ve had to do the following:
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/ CurrentJDK[/code]
This immediately fixed the issue and all terminal applications worked again.
Note: I’ve had manually set the “JAVA_HOME” and “JRE_HOME” variables in the “.profile” file. With the above setting I’ve had to remove those variables in order to make it work!
I initially removed the Apple installed Java 6 (1.6) installation manually, I removed the directory /System/Library/Frameworks/JavaVM.framework and other Java references (yes, I know it is/was a bad idea). Just installing Java 7 did not help nor does a system reboot. Also, Apple updates did not recognise that Java was gone. Also, installing Java 6 from Apple directly (download img) did not help. In short, nothing worked anymore.
The only solution was to get Pacifist (look for it on the web). Within Pacifist load the PKG (from the Java 6 image) and install the complete package and overwrite all existing installation. This will replace all the files I accidentally removed (the important system files) and got it all up and running again.