Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Java source on Mac OS X

I think my JDK is broken. I am on OS X 10.6.8.

I want to look in the sources when debugging in Eclipse, etc, but Eclipse can't find the sources, so I looked up the installed JREs and found this path with the title JVM 1.6.0 (MacOS X Default)

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

In Terminal I went to the directory /System/Library/Frameworks/JavaVM.framework/Versions and executed ls -al:

drwxr-xr-x  13 root  wheel  442  8 Sep 22:46 .
drwxr-xr-x  12 root  wheel  408  8 Sep 22:46 ..
lrwxr-xr-x   1 root  wheel    5  8 Sep 22:45 1.3 -> 1.3.1
drwxr-xr-x   3 root  wheel  102 21 Jul  2009 1.3.1
lrwxr-xr-x   1 root  wheel   10  8 Sep 22:45 1.4 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10  8 Sep 22:45 1.4.2 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10  8 Sep 22:45 1.5 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10  8 Sep 22:45 1.5.0 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10  8 Sep 22:45 1.6 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10  8 Sep 22:45 1.6.0 -> CurrentJDK
drwxr-xr-x  10 root  wheel  340  8 Sep 22:46 A
lrwxr-xr-x   1 root  wheel    1  8 Sep 22:45 Current -> A
lrwxr-xr-x   1 root  wheel   59  8 Sep 22:45 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

So Eclipse already has the proper JDK linked. Another test:

$ javac -version
javac 1.6.0_26

$ which javac
/usr/bin/javac

$ ls -al /usr/bin/ | grep javac
lrwxr-xr-x     1 root   wheel          75  8 Sep 22:45 javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac

So it all looks fine, but there is no rt.jar or src.jar Here is a screenshot:

A screenshot showing the jars in the current JDK.

So I try to reinstall it. I go to Apple's website and download this package: Java for Mac OS X 10.6 Update 5 Developer Package, file: javadeveloper_for_mac_os_x_10.6__10m3425.dmg. The installation finished successfully, but it doesn't change anything.

I show the last modified files on my computer, these are only some java tools, located in usr/share/java/Tools

  • Java VisualVM
  • Jar Bundler
  • Applet Launcher

There still is no rt.jar or src.jar in the java home directory.

like image 247
timaschew Avatar asked Sep 08 '11 22:09

timaschew


2 Answers

NOTE: This answer is old and for Apple Java 6. For Oracle Java you need to download the JDK as it includes src.zip.


The source is not included in the default Java download. You need to additionally install the corresponding development package available from ADC.

In addition, Eclipse has not yet been taught how to find the src.zip file and the dialogue cannot look inside packages.

On my 10.7, the above mentioned installation put src.zip in /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/src.jar

like image 198
Thorbjørn Ravn Andersen Avatar answered Oct 23 '22 10:10

Thorbjørn Ravn Andersen


From: http://lookfirst.com/2011/03/fix-missing-source-for-java-mac-os-x.html (adapt version #s and paths as needed)

  1. Go to http://connect.apple.com and download Java for Mac OS X 10.6 Update 4 Developer Package
  2. Install it.
  3. Open a Terminal.app window
  4. cd /System/Library/Frameworks/JavaVM.framework/Home
  5. sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar .
  6. sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar .
like image 38
TofuBeer Avatar answered Oct 23 '22 09:10

TofuBeer