Source code for Mac OS X Java Updates [duplicate]

I had the same problem today - I installed the Java Developer package from http://connect.apple.com, but couldn't find "src.jar" in /System/Library/Frameworks/JavaVM.framework/... anymore. On my machine, it's now in
/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/src.jar.

Update: For the latest version from March 2011, the jar is now:
/Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar

Once again, you'll have to download the new Java Developer package first.


What I do is as follows:

Download and install the Java Developer Kit (using your developer AppleId), current version 1.6.0_24-b07-334.jdk, and then in a shell, cd to the /System/Library/Frameworks/JavaVM.framework/Home directory.

Put in symbolic links to the jdk source files, src.jar, docs.jar and appledocs.jar, in the jdk you've just downloaded, that is:

sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar src.jar

and similarly for the other two jars.

Then, in Eclipse/Preferences, you can create a new Installed JRE by duplicating the existing one (the existing one points to something like /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home) and then select the new Installed JRE and remove the original.

The Eclipse Projects might need updating to point to the 'new' JRE, but the source and javadocs should now be available for the standard java stuff without further ado.

NB Ensure that the version of the jdk matches the version of your system Java for this to work properly.


Install java source, docs in 8 steps:

  1. Sign in with your Apple ID (http://connect.apple.com)

  2. Go to https://developer.apple.com/downloads/index.action

  3. Download Java for OS X 2012-00* Developer Package

  4. Install javadeveloper_for_os_x_ * .dmg.

  5. Go to Eclipse > Preferences > Java > Installed JRE

  6. Click Search...

  7. Choose JRE with location like /Library/Java/JavaVirtualMachines/1.6.0_your_jdk_filename.jdk/contents/home. In my case jdk file name was 1.6.0_33-b03-424.jdk.

    You can find the file name of jdk in terminal: ls -l /Library/Java/JavaVirtualMachines

  8. Now, when you try "open declaration" and get message "Source Not Found" press button Attach source... and paste /Library/Java/JavaVirtualMachines/1.6.0_your_jdk_filename.jdk/contents/home/src.jar


These are the exact steps that worked for me.

Go to the apple dev java downloads page and get the latest one you can (the apple dev web site will not let you download packages that are unsuitable for your OS version).
I installed Java Developer Package for Mac OS X 10.6 Update 5 (Disk Image).

Then I executed these commands:

sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_26-b03-384.jdk/Contents/Home/src.jar /System/Library/Frameworks/JavaVM.framework/Home/src.jar
sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_26-b03-384.jdk/Contents/Home/docs.jar /System/Library/Frameworks/JavaVM.framework/Home/docs.jar
sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_26-b03-384.jdk/Contents/Home/appledocs.jar /System/Library/Frameworks/JavaVM.framework/Home/appledocs.jar

Then I restarted Eclipse (I didn't have to create a new JRE).