Sunday 16 December 2012

Add the sun-provided platform specefic extensions to the apple-provided JDK source jar

Add the sun-provided platform specefic extensions to the apple-provided JDK source jar
The problem

The apple-provided JDK for mac osx systems, i.e. the developer version source JAR file doesn't contain the required sources for the platform-specific extensions provided by sun. When inspecting or debugging the JDK code via an IDE then that will result in displaying the decompiled version of these classes instead of the actual sources that should be shipped with the JDK distribution. However, the same sources for these extenstion packages (sun.*) are available from within the OpenJDK6, all what we need to do is to download/clone a copy of the OpenJDK6 sources and copy these over to the apple-provided JDK source JAR file to have the actual sources being displayed in your IDE while inspecting/debugging code.

How to do it?
  1. Navigate to the home directory where your apple-provided JDK is installed, you can do so using the following command:
    cd `java_home -v 1.6`
  2. Rename the original source JAR file that contains the source codes missing the sun.* platform extension packages, you can do so using the following command:
    sudo mv src.jar src.jar.orig
  3. Check out the latest copy of the OpenJDK6 sources, you can obtain a copy of the OpenJDK6 sources either from a ZIP file or via clonning a Mercurial repository, here we we will clone the latest copy from a Mercurial repository using the following command:
    hg clone http://hg.openjdk.java.net/jdk6/jdk6/
  4. Now we need to make a copy of the original source JAR provided by apple and extract it, later on we will add the missing sources into it before copying back into our JAVA_HOME directory
    cp src.jar.orig ~/tmp
    cd ~/tmp
    jar -xvf src.jar.orig
       
  5. Now we need to copy the missing sun packages from the OpenJDK sources into the content of the extracted jar, as follows:
    cp -R >The directory to your OpenJDK6 sources>/jdk/src/share/sun .
  6. After copying the missing sources we need to re-build the sources jar and move it back again into the JAVA_HOME where the apple-provided JDK is installed, we need to also make sure to restart our IDE after copying the new JAR for the changes to take effect.
    jar -cvf src.jar *
    sudo cp src.jar `java_home -v 1.6`
       

No comments:

Post a Comment