views:

75

answers:

3

Hi,

With the latest Java update on MacOSX 10.6, Eclipse does not find the Java sources anymore.

I am not exactly sure (i.e. don't remember anymore) if I have downloaded the sources manually in the past and put them somewhere or if MacOSX provided them and Eclipse found them automatically.

Does MacOSX have the sources somewhere? (Please no assumptions here. I really want to know that.)

If not, where can I get them?

+1  A: 

The src.zip is only available in the JDK, not in the JRE. In Mac OS X, it should be located in /System/Library/Frameworks/JavaVM.framework/Versions/Current/Home as src.jar.

BalusC
I have not installed anything (it is all there preinstalled in MacOSX). But I must have the JDK, otherwise I would not be able to compile anything. And I have `/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home` but there is no `src.jar` in it.
Albert
You can get it from http://developer.apple.com/java/download. You only need to be a registered Apple member. See also [this blog](http://jimbarritt.com/non-random/2009/12/02/java-sources-src-jar-for-jdk-on-osx/) and [this question](http://stackoverflow.com/questions/2767220/is-there-a-src-jar-in-osx).
BalusC
I am registered but I cannot really open that links. It always redirects me to the main ADC download site. When I go to the Java section there, I can download Java for Mac OS X 10.6 Update 3 Developer Package which I just did. I installed it but I still don't find the `src.zip`.
Albert
That's great :/ Apple+Java has always been a vague relationship.
BalusC
+1  A: 

On Mac OS X 10.5.8, after updating to Java 1.6.0_22 and installing the most recent developer update dated 20-Oct-2010, src.jar for Java 6 is not present.

$ find /System/Library/Java /System/Library/Frameworks -name src.jar
/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/src.jar
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/src.jar

Navigating to source in NetBeans 6.9.1 says compiled code for all constructors and methods, e.g. java.awt.Point:

public Point() {
    //compiled code
    throw new RuntimeException("Compiled Code");
}

It may be possible to extract a usable JAR from a previous update, as suggested in this thread.

Addendum: On NetBeans, the default platform's location is an attribute in the file ~/.netbeans/6.9/config/Services/Platforms/org-netbeans-api-java-Platform/default_platform.xml:

<sources>
    <resource>jar:file:/Library/Java/JavaVirtualMachines/
        1.6.0_22-b04-307.jdk/Contents/Home/src.jar!/src/
    </resource>
</sources>

Alternatively, the file /Library/Java/Home/src.jar may be referenced:

<sources>
    <resource>jar:file:/Library/Java/Home/src.jar!/src/</resource>
</sources>
trashgod
+3  A: 

After installing the most recent Java update you'll find src.jar under

/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home

That's where I pointed "JRE home" for Java 1.6 in Eclipse to. Everything works as expected (until now :)

Sebastian Beigel
What... :P Have I really always overlooked this? I think I always have looked at the JDK which is installed in `/System/Library/...`. I didn't knew there was also *another* JDK in `/Library/...`.
Albert
I don't have /Library/Java/JavaVirtualMachines - I think that must be something Sebastian put in himself.
Mike Baranczak
@Mike Baranczak: You should have `/Library/Java/Home/src.jar`. The newer one in `JavaVirtualMachines` is a developer release.
trashgod
@Sebastian Beigel: +1 Thanks! I added some related NetBeans findings in an adjacent answer.
trashgod