Tag Archive for coding

Using both Java 1.7 and 1.6 on Mountain Lion

Here’s the situation you need to use both JDK 1.7 and JDK 1.6 for different projects you are working on with Mac OS X. You already have Java 1.6 installed and ran the installer for Java 1.7 from Oracle but no matter what you do java -version will only show 1.6.

Here’s what you do to use 1.7 run the following:
sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

To use 1.6 run the following:
sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
sudo ln -s /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

Note you may have to adjust for the exact version for example if you installed jdk1.7.0_12.jdk.

Here’s an example:
thor:~ dan$ sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
thor:~ dan$ sudo ln -s /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
thor:~ dan$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)
thor:~ dan$ sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
thor:~ dan$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
thor:~ dan$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

Share