Thursday, December 20, 2012

Set up Java 7, Eclipse and Netbeans on Retina Macbook Pro


- Bad news: Netbeans 7.4 now requires Java 7 to run, which means the hack to force IDE to use Apple's Java 6 does not work anymore.

- Good news: According to Bug 215141, the Retina display issue is finally fixed in JDK 7u40+ and early access build of JDK 8! I just installed JDK 7u40 and Netbeans 7.4 RC2, and I can confirm that Retina display finally works!!!

I can happily announce that you guys can skip the rest of the post now. You can simply download latest JDK 7 7u40+ or JDK 8, and then install either Eclipse or Netbeans, Retina display should work as expected. No more blurriness!!!

Just got my laptop updated by my generous employer, it is a Retina Macbook Pro (rMBP). This is the laptop/computer with the highest performance I ever used, and the most expensive one too.

Here are the steps to set up Java 7 (J2SE 7u10), Eclipse (4.2.1) and Netbeans (7.2.1) on the rMBP as of this writing.

1. Install Jave 7.

Starting from Mountain Lion, Java is not installed by default. So, if you run a Java application, you might be prompted to install the Apple Java 6, just like this screenshot shows:

Unless you have Java applications that must use Java 6, I really don't see the point of installing both Java 6 and 7, especially now Oracle provides J2SE 7 for Mac already. There was a time when Oracle has not officially released J2SE 7 for Mac and I had to install OpenJDK to try out Java 7 new features.

So, simply to go Oracle Java 7 download page and download "Mac OSX x64", as of my writing it is jdk-7u10-macosx-x64.dmg. Install it and you will get it installed to:

To verify that you have installed it successfully, simply type "java -version" and you should see the following:

$ java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
You also need to add JAVA_HOME environment variable by inserting this line to ~/.bash_profile:

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
java_home is a command to return to the Java home directory for the current user, -v 1.7 filters Java versions for 1.7.

2. Install Eclipse.

Installing Eclipse without installing Java 6 is quite tricky. I am simply surprised that Eclipse has not support Java 7 out of box yet. If you haven't installed Java 6, the Eclipse will simply give the above error message and won't start at all. There are bugs filed for this issue (bug 382972, bug 374212, etc.) and it is very disappointing that this problem has not been solved yet.

After some online search, here is the hacky way:

Download and install Eclipse, I got Eclipse 4.2.1

- Create a symbolic link with the name of the Java 6 to hoax Eclipse that you have Java 6 by doing the following:

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
After this hack, Eclipse will start correctly (you will need to do the ctrl+click trick since it is not downloaded from App Store and considered as from an untrusted source).

The above screenshot shows the Installed JREs in Eclipse Preferences, so funny that the symbolic link also shows up ;-)

To be frank, I am really disappointed by this Eclipse installation process. First, it should be installable right from App Store. Second, it should be bundled with JDK/JRE 7 directly (they actually have bugs for that, e.g. bug 374791, but not fixed yet).

3. Install Netbeans.

The installation process for Netbeans is much smoother than Eclipse. You simple download and install it and it automatically picks up the Java 7 installed in /Library/Java/JavaVirtualMachines/ and works out of box! No wonder lots of people actually switched from Eclipse to Netbeans.

4. The Retina Fix.

Note: currently, this Retina fix only works for Apple Java 6, not Oracle Java 7. Hope similar fix for Java 7 will be released soon. However, if you are running Apple Java 6, you can try this fix now. This is the bug to track the progress of Oracle fixing this issue.

Maybe because the rMBP is too expensive, many applications are not yet supporting Retina display out of box. In the case of Eclipse and Netbeans, you need to hack their Info.plist file a bit, here is how:

- First install Apple JDK 6. You will need to remove the symbolic link created in Step 2. Then download it from Apple and install it.

- Locate and, they are the ones that you double click to run. should be in the unzipped directory from the tar.gz Eclipse package you untarred. Netbeans by default installs into Applications/Netbeans.

- Right click on .app, and click on "show package contents". Use a text editor to edit Contents/Info.plist. Insert two lines before the closing </dict></plist> tags:


- Now, we need to make Eclipse and Netbeans to run using Apple JDK 6 instead of the default Oracle Java 7.

To make Eclipse using Apple Java 6 instead of Java 7, you need to update eclipse.ini. Using the same way to show contents of, edit Contents/MacOS/eclipse.ini and add -vm option:

An alternative is to edit Contents/Info.plist and add inside <key>Eclipse</key><array>...<array>
To verify Eclipse is started with the correct JDK/JRE, in Eclipse, go to "About Eclipse" -> "Installation Details" -> "Configuration" and see the "java.runtime.version".

Maybe due to the Mac caching the previous, changing Contents/Info.plist does not work immediately. You need to make a copy of the, name it like Double click on and enjoy Eclipse in Retina.

Here is a comparison of the info for and (right click then select "get info"), notice for, "open in low resolution" check box has been unchecked!

To make Netbeans using Apple Java 6, similarly, you can edit the Netbeans config file. Show contents of, edit Contents/Resources/Netbeans/etc/netbeans.conf and add netbeans_jdkhome option:

After saving the edit, restart Mac and Netbeans. You should see the Retina display working with Netbeans now. No idea why Netbeans does not need to copy to create a new app to work, but it certainly is much easier than Eclipse.