Enabling Java 7 on Mountain Lion

Solution 1:

Apple's tools don't see Java 7, Oracle's tools don't see Java 6; it's all a bit ugly. Luckily there's an ugly fix to go with it!

Normal Mac Java 6 running on 10.8:

java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)

Install the Java 7 JDK (not just the JRE) from Oracle.

Move the system java out of the way (so you can get it back if you want):

sudo mv /System/Library/Java/JavaVirtualMachines/1.6.0.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdkx

Then symlink 7 in place of 6:

sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

and voila:

java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

I've not had trouble with any java apps so far (apart from java preferences which checks which java it's running under).

There's probably a better way of doing this, but it works for me.

Solution 2:

To switch to Java 7 for when Java is run from the terminal, I added the following line to ~/.profile:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home

Solution 3:

$ cp -r /Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk /System/Library/Java/JavaVirtualMachines/

$ sudo ln -sF /System/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk CurrentJDK

$ java -version java version "1.7.0_12-ea" Java(TM) SE Runtime Environment (build 1.7.0_12-ea-b05) Java HotSpot(TM) 64-Bit Server VM (build 24.0-b26, mixed mode)