How do I view JRE's source code in Eclipse?

JavaEclipse

Java Problem Overview


Using Eclipse I want to view the source code for a core Java class (E.g. java.util.concurrent.ConcurrentHashMap) but when I navigate to the source using 'Open Declaration' it says 'Source not found' and gives me the option to attach the source.

My question is; how do i attach the source? Where do i get the source .jar from for the java.util.concurrent library?

Java Solutions


Solution 1 - Java

When you are coding in Eclipse, press CTRL and click on any core Java class name in your source. Eclipse will now show a screen saying you don't have the sources installed. However, in this screen there is a link saying "Attach source...". Click that link and import the src.zip file from your JDK installation directory (src.zip). This should do the trick

Solution 2 - Java

You need to have the JDK installed. Then you can look in JDK_INSTALL_DIR\src.zip

For me it is C:\Program Files\java\jdk1.6.0_11\ (depends on your current version)

You don't need to get a special open source version.

Solution 3 - Java

There are a few good answers here on where to get the source. But a word of caution: I'd be wary about how you use it (if you're using it simply for reference). The API documentation is the only contract you should code against, and is what the developers will keep consistent/intact between releases. I wouldn't use the source find out implementation details and then code my applications with regard to those implementation details, as they may change between releases.

Solution 4 - Java

You should be able to see "JRE System Library [jdk1.x.xxxx]" when you look at your project's Java Build Path.

You can access the project build path configuration screen by: right clicking on the project -> Build Path -> Configure Build Path... You should be able to see the JRE System Library entry at the bottom of the list.

The easiest way to view the source for the class is to use the "Open Type" shortcut. The default for this shortcut is: Ctrl + Shift + T". The class you're looking for should appear as you type it's name.

Solution 5 - Java

You can go to http://openjdk.java.net/ and download the latest builds of the openJDK project. I think this should give you what you need.

Solution 6 - Java

For ubuntu, install openjdk-6-source and use /usr/lib/jvm/java-6-openjdk/src.zip

Solution 7 - Java

If you can't find the actual source you can also use a decompiler to regenerate source from the class file.

Personally I use JAD combined with the JADClipse plugin to view source in Eclipse.

Solution 8 - Java

Right click on the project -> Build Path -> Configure Build Path. Now edit your jre > select 2nd option alternate jre -> select any jdk (not jre). Finish, Now open any class by ctrl + click, Its source code will display.

Solution 9 - Java

Outside Eclipse you can see the JDK sources on javasourcecode.org. On this page you can switch from the oficial API documentation to the source code and viceversa.

Solution 10 - Java

You can use 'Eclipse Class Decompiler integrates JD, Jad,' from Eclipse Marketplace.

From the find box in the Eclipse Marketplace write: 'jad' and you would find it.

Solution 11 - Java

src.zip file is present in installed jdk folder : ..\Program Files\Java\jdk1.8.0_131

Provide this path on the screen showing Attach source... worked for me.

Solution 12 - Java

we can see C:\Program Files\Java\jdk1.8.0_73\src.zip where C:\Program Files is a home directory where I have installed the java.

in eclipse, it will show like Source not found. form there link will come like browse source. browse the link C:\Program Files\Java\jdk1.8.0_73\src.zip and attach it. now you can see your source code.

Solution 13 - Java

@jjnguy suggestion worked for me. But make sure you have also changed the default compiler as well. Right clickon th project-->Java Compiler->Click on the link under JDK Compliance(right section).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLearningJavaInLondonView Question on Stackoverflow
Solution 1 - Javauser182013View Answer on Stackoverflow
Solution 2 - JavajjnguyView Answer on Stackoverflow
Solution 3 - JavaRob HruskaView Answer on Stackoverflow
Solution 4 - JavaElias PetersonView Answer on Stackoverflow
Solution 5 - JavaBrian FisherView Answer on Stackoverflow
Solution 6 - JavaruedisteView Answer on Stackoverflow
Solution 7 - JavaMichael RutherfurdView Answer on Stackoverflow
Solution 8 - JavaRockyView Answer on Stackoverflow
Solution 9 - JavaFrancisco J. Güemes SevillaView Answer on Stackoverflow
Solution 10 - JavaShahar GluzmanView Answer on Stackoverflow
Solution 11 - JavaNidhi SharmaView Answer on Stackoverflow
Solution 12 - Javapushpendra yadavView Answer on Stackoverflow
Solution 13 - JavaHireinView Answer on Stackoverflow