In Eclipse, when you press Ctrl button and click on any Class names, the IDE will take you to the source file for that class. This is the normal behavior for the classes you have in your project.
But, in case you want the same behavior for Javaβs core classes too, you can have it by attaching the Java source with the Eclipse IDE. Once you attach the source, thereafter when you Ctrl+Click any Java class names (String for example), Eclipse will open the source code of that class.
To attach the Java source code with Eclipse,
- When you install the JDK, you must have selected the option to install the Java source files too. This will copy the src.zip file in the installation directory.
- In Eclipse, go to Window -> Preferences -> Java -> Installed JREs -> Add and choose the JDK you have in your system.
- Eclipse will now list the JARs found in the dialog box. There, select the rt.jar and choose Source Attachment. By default, this will be pointing to the correct src.zip. If not, choose the src.zip file which you have in your java installation directory.
- Similarly, if you have the javadoc downloaded in your machine, you can configure that too in this dialog box.
Done! Here after, for all the projects for which you are using the above JDK, youβll be able to browse the Javaβs source code just like how you browse your own code.
Reference: Attaching Java source with Eclipse IDE from Veera Sundar one of our JCG partners.
Related Articles :
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Thank you!
We will contact you soon.
Tags
Eclipse
π Photo of Veera Sundar
Veera SundarAugust 18th, 2011Last Updated: October 21st, 2012
Veera SundarAugust 18th, 2011Last Updated: October 21st, 2012
2 250 1 minute read

This site uses Akismet to reduce spam. Learn how your comment data is processed.
If itβs a third party source code we want to add and in case we have a Maven project, m2Eclipse or with the newer name m2e plugin can take care of that either automatically downloading the source in a βF3β attempt on a class or explicitly by right clicking on the jar > Maven > add sources/javadocs
Disclaimer: I am biased!
I would suggest you to use my open source plugin βJava Source Attacherβ which can be found on Eclipse marketplace. It would do the tedious work of looking for the source code of your libraries from popular Maven repositories and do the attaching automatically.
URL: https://marketplace.eclipse.org/content/java-source-attacher