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.
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.
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.
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.
P.S: Menu structure is taken from Eclipse 3.4.0 version.




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.
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
Thanks my problem solved by 1 st solution!!!!!!!!!!!
superb work. I was worried for a long time how to use this feature in eclipse..
Thanks…
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.
Thanks for the post.
It helped me.
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 ..
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
> 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.)
Generally jar files are created with and without source files as you mentioned.
Thanks for the tip Dan.
Thank you for this! I’d done it before but had forgotten.
you’re welcome.
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 ?
Hi,
These external source code files are generally released with the library you’re trying to use. They are distributed as external archive files (src.zip in our example) or jar files with source codes are included in. You have to download it manually.
Happy coding.
Nice one.. thank you