Sunday, June 5, 2011

Downloading OpenJDK7 Binary for Mac OS X

 NetBeans IDE 7.0 has support for the bleeding edge OpenJDK 7.0 build release.  Even if Mac OS X does not have an official binary distribution on the Open JDK site yet, we can still get a DMG bundle of the latest build of Open JDK7 to test on Mac OS X.

Let us go through steps we need to perform to install and test OpenJDK7 on Mac OS X.  The OpenJDK7 latest binary is available on the Google Code site http://code.google.com/p/openjdk-osx-build/

The latest build available there today is seen as b144 which is the latest build available on the OpenJDK7 download page also.  This bundle is available in 32 as well as 64 bit version.


They have created a nice DMG bundle which shows the Java mascot when we open the DMG.


The installation starts as a usual Mac OS X installer bundle.  As seen from the below image this version takes 179.6 MB on disk.


Once we have installed the OpenJDK7 latest binary build.  We can start the Java Preferences application from the Spotlight and can see two more JDK instances available in the list of JDK available.  One for 32 bit and one for 64 bit.

If we choose we can set the JDK7 version default here.  I choose not to set it as default yet as it is not an official version from OpenJDK7 site.  We can still use this JDK from NetBeans by registering it as a JDK platform.


For registering the JDK7 as platform on NetBeans IDE 7.0 open up the Java Platform Manager from Tools > Java Platforms menu.  The new JDK7 will not be seen yet.  We will have to press the Add Platform button.


NetBeans IDE will point you to correct Java Library directory from where you can choose the openjdk-1.7 instance of the java platform.


When we select the openjdk-1.7 folder NetBeans IDE correctly fills all the required information and presents a prefilled dialog boz for Add Java Platform and we just have to click Next.


JDK 1.7 will start appearing in the available Java Platforms list.  As we can see NetBeans detects all the required files and documents required for registering the JDK 1.7 platform.


Now we can start any Java project and set the Java Platform as JDK 1.7.  For that we will have to open the Project Customizer by right clicking the project and choosing the Properties menu.

We need to change the Java Platform entry in the Libraries node first.


Once the Java Platform is set as JDK 1.7 in the Libraries Node it becomes available in the Sources Node also in the Source/Binary Format combo box.  We will have to set this as JDK 7 also.


Now this project is set to be compiled and run under Java 7 platform.  We can test this by adding some generics statement and NetBeans IDE offers a hint to use diamond operator (Project Coin)


NetBeans IDE will also apply those changes to the code when we select the hint as seen in the image below.


So this is how we can install latest JDK 1.7 on our Mac machines and test the JDK 7 version from NetBeans IDE 7.0 which supports JDK 1.7 features now.

with regards
Tushar Joshi, Nagpur

8 comments:

  1. Hey, great post. I think I got everything working with Netbeans 7 and OpenJDK7, however, my observations were slightly different from yours. Mainly, in the step where you Add Java Platform in Netbeans, I did not have the openjdk-1.7-x86_64 entry; mine only showed 1.7.0.jdk (at /Library/Java/JavaVirtualMachines/). And then in order to get the Next button enabled to progress forward, I had to navigate down to the /Contents/Home/ directory. So where your classpath is /Library/Java/JavaVirtualMachine/openjdk-1.7-x86_64/jre/... mine is /Library/Java/JavaVirtualMachine/1.7.0jdk/Contents/Home/jre/... Any idea why the difference? I'm on a Macbook Pro OS X 10.6. I installed the same versions of everything as you, I believe.

    ReplyDelete
  2. Mark,

    Thanks for the comment with your findings. I already had one older build of JDK7 installed on my MacBook Pro hence I may have directory different than yours.

    Your findings may help someone who is following the same steps as they confirm one more path for successful installation of JDK7 on Mac OS X.

    I believe even if the steps were different from some point you were successful in the installation and could test NetBeans IDE 7.0 support for the new features.

    with regards
    Tushar Joshi, Nagpur

    ReplyDelete
  3. Thanks Tushar. One note for anyone else reading this, I did get some error saying that the JDK7 I specified (same download as Tushar's version) could not be used. I just kept going and everything seems to be ok. I'm able to use the JDK7 new features, so far. It's just nice to have an environment on which to test and get familiar with JDK7!

    ReplyDelete
  4. I also agree. This was the best post on updating to Java SE 7. However, when I try to add a platform, the openJDk-1.7... doesn't show up. The only thing that shows up is the 1.6.0.jdk folder. I don't know how to have the 1.7.0.jdk show up as I downloaded using the same steps as you did.

    ReplyDelete
  5. Thanks all for writing comments and concerns. I would like to suggest all to use the latest Oracle JDK7 preview release for Mac http://jdk7.java.net/macportpreview/ released by Oracle.

    with regards
    Tushar

    ReplyDelete
  6. Thanks Tushar, it really help me. Now i would like see if you know how to configure netBeans to use javaFX. Thankyou!!

    ReplyDelete
  7. Hi. I had the same problems as others here, but I noticed in Mark's post that the directory was /Library/... while my NetBeans was looking in /System/Library/...
    When I took the /System off the front, it could find the OpenJDK and I could set it as my platform.
    Then I followed the other steps and it's all good.

    ReplyDelete
  8. I have a question about NBTaskFocus, I know that the idea is coming from Mylyn in Eclipse. For Mylyn in Bugzila if you search for an specific issue you can see that there is an attachment file called "Mylyn-context.zip" which includes all of the files which were interacted for fixing that issue. I want to know is there any way I can find the list of files which have been added to Task panel for fixing a bug in Bugzilla for NetBeans projects?
    I mean is there any project in NetBeans which developers use to attach the list of files in task panel to bug or attach to the repository. Thanks.

    ReplyDelete