Eclipse: How attach Java source

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,

  1. 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.
  2. In Eclipse, go to Window -> Preferences -> Java -> Installed JREs -> Add and choose the JDK you have in your system.
  3. 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.
  4. 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 :
Related Whitepaper:

Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code

Use Java? If you do, you know that Java software can be used to drive application logic of Web services or Web applications. Perhaps you use it for desktop applications? Or, embedded devices? Whatever your use of Java code, functional errors are the enemy!

To combat this enemy, your team might already perform functional testing. Even so, you're taking significant risks if you have not yet implemented a comprehensive team-wide quality management strategy. Such a strategy alleviates reliability, security, and performance problems to ensure that your code is free of functionality errors.Read this article to learn about this simple four-step strategy that is proven to make Java code more reliable, more secure, and easier to maintain.

Get it Now!  

2 Responses to "Eclipse: How attach Java source"

  1. Dimitris says:

    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

  2. Thai Ha says:

    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

Leave a Reply


− 4 = two



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books