Tuesday, September 4, 2012

Install JDK 7 on Mac OS X 10.6.8

I have the default Java development environment installed in my Mac OS 10.6.8 and everything runs fine but the new project requires JDK 7. It took me several hours to have everything works properly so I think I should summary the process here to help anyone who may need to go through the same process. So... below is the steps:

1. Upgrade Mac OS to Lion 10.8.1 or later as Java 7 installation only works on version 10.7.3 or later. You can do this via the App Store.

2. Download JDK 7 (I use the update 7 version) for Mac from Oracle website. Currently, it's here http://www.oracle.com/technetwork/java/javase/downloads/jdk7u7-downloads-1836413.html

3. Install JDK

4. You would probably see that some command line program (e.g. ant) doesn't work after that. You may get error message like
JAVA_HOME is not defined correctly.We cannot execute /System/Library/Frameworks/JavaVM.framework/Home/bin/java

To fix immediately, you can type (from command line)

export JAVA_HOME="`/usr/libexec/java_home`"

or you can do the following:
a. sudo vi ~/.bash_profile
b. insert this line
    export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

You would need to restart.

5. If you try to open Eclipse, you may see this popup message "To open “Eclipse,” you need a Java SE 6 runtime. Would you like to install one now?". You could get around this by using this trick (credit go to http://apple.stackexchange.com/questions/58203/mountain-lion-with-java-7-only)
sudo mkdir /System/Library/Java/JavaVirtualMachines
sudo ln -s /Library/Java/JavaVirtualMachines/jdk.1.7.0_07.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

My eclipse works perfectly after this.

Hope you find this helpful.