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 ( 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.


Posted in Tips & Tricks.

Tagged with , , .

21 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:programsjavajdk-1.6

    Eclipse will automatically detect and attach the 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 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..


  5. imi says

    Hi all.

    I have attached sources for my java jdk
    (/usr/lib/jvm/java-6-sun- , 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.


  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


    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!


  9. Dan says

    > You can use the above techniques for other libraries…

    One additional technique is to include the source in the jar. I found that handy for large projects with many users, because it saves each user the manual steps of attaching source. (The source files and compiled files share the same directory structure, so in every directory, every .class file has a .java file with the same name.)

    • Abdullah Cetin CAVDAR says

      Generally jar files are created with and without source files as you mentioned.
      Thanks for the tip Dan. :)

  10. Sid says

    Thank you for this! I’d done it before but had forgotten. :)

  11. john says

    In method 3:
    “Select the source code file (External File) ”
    What does that mean and how do you do it ?
    What are these external files ?

    • Abdullah Cetin CAVDAR says

      These external source code files are generally released with the library you’re trying to use. They are distributed as external archive files ( in our example) or jar files with source codes are included in. You have to download it manually.
      Happy coding. :)

  12. saidesh says

    Nice one.. thank you

  13. says

    Hi, I do think this is a great web site. I stumbledupon it ;) I will come back yet again since i have saved as
    a favorite it. Money and freedom is the best way to change, may
    you be rich and continue to help others.

  14. vamsi says

    good … worked for me

  15. Dead Trigger 2 Hack says

    Hi th?re would you mind l?tting me know which web host you’re using?
    I’ve loaded ?ou? blog in 3 completely different ?eb browsers and I must say this blog loads a lot faster
    then m?st. Can you suggest a good hosting pro?i?er at
    a honest p??ce? Che?rs, I appreciate it!

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 […]

  2. Eclipse how to see the Java file instead of class file | PHP Developer Resource linked to this post on May 29, 2012

    […] you have the source available then use Attach Source feature. If not then any decompiler eclipse plugin is fine. My preference is JD-Eclipse. […]

Some HTML is OK

or, reply to this post via trackback.