I cannot for the life of me attach the java source code to eclipse so I can see the inner workings of the language. Not even something as simple as the String Class.
when I run java -version this is what I have:
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
I am downloading the java souce from: http://download.java.net/jdk6/source/
And in eclipse when I attach it It says:
The JAR file "C:\Program Files\Java\jre6\jdk-6u14-fcs-src-b08-jrl-21_may_2009.jar"
has no source attachment.
What am I doing wrong?
To attach JDK source so that you refer to Java Source Code for code look-up which helps in learning the library implementation and sometimes in debugging, all you have to do is:
In your Eclipse Java Project > JRE Reference Library locate rt.jar. Right click and go to Properties:
Select "Java Source Attachment" on the right and to the left select "External Location" and click on "External File" Button and locate "src.zip" file in your $JAVA_HOME path in my case for my windows machine src.zip location is: C:/Program Files/Java/jdk1.7.0_45/src.zip.
You are done now! Just Ctrl + click on any Java library Class in your project code to look-up the source code for the java class.
The option provided by"praveenak" can also be applied to any other jar files with source file provided. For example, for JavaFx, we right click jfxrt.jar, select "Properties" and enter jdk1.8.0_05/javafx-src.zip for "Path" under External location.
You need to attach java sources which comes with JDK(C:\Program Files\Java\jdk1.8.0_71\src.zip).
Steps(**Source: link):
if you are add jre and jkd path, remove jre install path, keep jdk path is work
What worked for me (with JDK7) was the following:
Alternatively, if you don't want to write to your JDK folder, you could also attach src.zip to (at least) rt.jar in eclipse in the Window | Preferences menu in Java | Installed JREs.
If you're not comfortable with downloading the sources from GrepCode, you could also get them from openJDK directly. This requires requires a bit more effort, though. Replace step one above by the following steps:
A third alternative to acquire src.zip is to download the unofficial OpenJDK builds from here. The src.zip is contained within the downloaded zip.
Answer For Eclipse 2019 With ScreenShots
rt.jar
from JRE systems library, click on corresponding drop down to expandSource attachment none
, Click on Source Attachment
Button, Source attachment configuration window will appear, Select external location
src.zip
file from jdk folder, say ok ok finishissue resolved here :
"Windows/Preferences": Java > Installed JREs:
then set/update JRE HOME : C:\Program Files\Java\jdk1.8.0_221\jre
should try this.
The easiest way to do this, is to install a JDK and tell Eclipse to use it as the default JRE. Use the default install.
(from memory)
Open Window -> Prefences. Select Installed Java runtimes, and choose Add. Navigate to root of your JDK (\Programs...\Java) and click Ok. Then select it to be the default JRE (checkmark).
After a workspace rebuild, you should have source attached to all JRE classes.
Old question, be here's what I ended up using Java Source Attatcher plugin: http://marketplace.eclipse.org/content/java-source-attacher#.U85j4rF-N7s
It can provide source for different opensource projects. One weird thing thou, if you have libraries under libs folder, you cannot attach from there, but you need to attach source clicking on jar displayed under "Libraries from external".
You don't necessarily need to add the source, but you rather may need to remove a JRE that does not have the source attached.
On looking at the "installed JRE's" I saw that my JDK was setup properly with source, but the default JRE on the machine had no sources. Eclipse was defaulting to that when looking for source.
I just used the remove button to expel the JRE, leaving my JDK. I then hit F3 and the source was there. Yeah!
Easy way that just worked for me:
Then the project will detect it and add the new libraries from the JDK. At the end of this process it looks like the screenshot I attach.
Just remove the JRE in Preferences>Java>Installed JRE and add the folder of your JDK. If you just add JDK but still leave JRE it won't work
Source: Stackoverflow.com