Skip to content


3 Ways of JDK Source Code Attachment in Eclipse

You wanna look at a JVM class while you are coding and you cannot. Here is the solution.

First of all, download your related JDK source code files unless you already have it. In general, source code is included in the JavaSE bundle and located under the root directory of your installation (src.zip mostly).

1. Try to “Open Decleration (F3)” to any JVM class (i.e String class). You will take “Source Not Found” message and below it you will see Attach Source… button. Press it, select the source code file (External File…) and press OK.

Method 1

2. Go to Project > Properties > Java Build Path > Libraries and expand JRE System Library [your jre version] then, rt.jar. Select Source attachment, click Edit…. Select the source code file (External File…) and press OK.

Method 2

3. Go to Window > Preferences > Java > Installed JRES and click Edit… for your desired JRE. Expand rt.jar, select Source attachment and click Source Attachment…. Select the source code file (External File…) and press OK.

Method 3

You can use the above techniques for other libraries that you need to navigate/discover if their source codes are in your hand.

And you’re OK now. Happy coding. :D

P.S: Menu structure is taken from Eclipse 3.4.0 version.

Related Posts

Posted in Tips & Tricks.

Tagged with , , .


9 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Thorbjørn Ravn Andersen says

    Try installing a JDK, and adding the root of the installation as a Java Runtime to Eclipse.

    I.e. c:\programs\java\jdk-1.6

    Eclipse will automatically detect and attach the src.zip. Additionally the latest build I downloaded was built with debug info so the local variables are visible when stepping through. Very nifty.

  2. nrkkalyan says

    Download jdk-6u18-ea-bin-b05-windows-i586-debug-18_nov_2009.jar from http://download.java.net/jdk6/ then run

    java -jar jdk-6u18-ea-bin-b05-windows-i586-debug-18_nov_2009.jar

    THIS WILL INSTALL src.jar and thus you can attach it in eclipse

  3. Shreyas says

    Thanks my problem solved by 1 st solution!!!!!!!!!!!

  4. Nuwan Arambage says

    superb work. I was worried for a long time how to use this feature in eclipse..

    Thanks…

  5. imi says

    Hi all.

    I have attached sources for my java 61.6.0.24 jdk
    (/usr/lib/jvm/java-6-sun-1.6.0.24/src.zip) , but still I haven’t whole class sources (java.* packages are ok, but not sun.* packages).
    For example: java.util.TimeZone is ok, sun.util.calendar.ZoneInfo is wrong.

    I was wondering if someone could help me with this issue :)

    Thanks a lot.

    Imi.

  6. Learner says

    Thanks for the post.

    It helped me.

  7. Dhaval says

    Thanx a lot dude …
    I searched for this help since about 2 days ….
    even the website of Eclipse doesnt provide such simple and easy help….
    thanx a lot … really was very useful .. :)

  8. Christof says

    Hi!

    Thank you very much for that hint! Since I started the first time with a small java project I’m troubled by that “source path not found” problem of the debugger. I spent at least 2 hours to solve it. The nasty thing is that appearing of the trouble is varying from class to class. Without knowing the nature of the problem its unpredictable.

    So, now it’s solved! Thank you!

    Christof

Continuing the Discussion

  1. Click F3 does not navigate to source code - Java Forums linked to this post on September 16, 2010

    [...] 3 Ways of JDK Source Code Attachment in Eclipse at cavdar.net [...]



Some HTML is OK

or, reply to this post via trackback.