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?
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
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.
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.
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.
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.
For ubuntu, install openjdk-6-source and use /usr/lib/jvm/java-6-openjdk/src.zip
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.
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.
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.
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.
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.
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.
#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).
Related
I am finding Java classes by using ctrl + shift + t, I click on the class I wish to see (example Scanner or Random in java.Utils) the type hierarchy for and it opens a tab that says, "Source not found." I read an answer that said my build path was not correct, but my programs uses these with no problem. Can I fix this so I can start to study type hierarchy or am I doing something wrong? Page after I click the class in menu
Your IDE can find the compiled Java classes, but not the Java source.
You may find a src.zip in your JDK folder - try to attach that in Eclipse's JRE/JDK setting.
If you want to see the all jar file content you can install eclipse Java Decompiler Plugin
JAD Decomplier plug-in for Eclipse version 3.x and 4.x.
update site: http://feeling.sourceforge.net/update
Steps:
Open Eclipse IDE.
Click Help->Install New software Paste above URL and give name as
JAD.
Select the Eclipse Class Decompiler Click on Next and accept
agreements Install it.
Restart Eclipse and check now.
Earlier I used Eclipse. Recently I have started using IntelliJ. I found that the IntelliJ equivalent of Eclipse keyboard shortcut F3 (view source) is F4.
But, when I use that I get the source in the following format.
It does not show complete source, i.e method implementation is not being shown. I have placed src.zip in the java sdk folder where Java is installed. I have added the src.zip in the project libraries too. In eclipse I can just attach source if it can't find one.
I have seen answers of relevant questions but couldn't follow. So,
How to attach the Java source in IntelliJ?
Detailed answer will be appreciated.
Thanks in advance.
Source is found in JDK folder, example - C:\Program Files\Java\jdk1.7.0_25\src.zip. JDK must be downloaded first, of course.
You should attach your source code to your project, get into Project Structure, click Global Libraries, add the source code jar, usually end with sources.jar, now you can see the source code.
you can see the Sources and JavaDocs under the Classes.
Found the answer.
Press ctrl + shift + alt + s
Select SDKs under platform settings.
On the right hand side there will be Sourcepath tab
Add the downloaded src.zip of java to the sourcepath
You can also add the API documentation under the Documentation Path in the same way by adding the downloaded API docs
I found I had to add the dependency jars under the model: i.e.
project structure ->
project settings ->
Modules (select the module where it has problem) ->
Dependencies (on the right handside pane) ->
click "+" ->
library -> then select all the libraries i needed (even though it is available at the root of my sbt project, i had to do this for the module i am interested).
also, i kept the library dependency at the build.sbt to be 'compile' scope instead of 'provided'. but sometime you want your dependency to be provided only (such as spark, or hadoop, in this situation)
I'm trying to debug a program that calls a function in the HashSet class, but I get a message saying: Source not found. I know this is something with not finding the library files. Please, can someone guide me to how I can set it up? Which library files should it be pointing to?
Thank you very much for any pointers.
Finally got around to doing this awhile ago and I love it.
First you need to download the Java source. I got mine here (look for "Java SE 6 JDK Source Code"): http://www.oracle.com/technetwork/java/javase/downloads/index.html. Download that and stick it somewhere on disk that you can find easily. Keep in mind that the JAR you download has to actually be "installed" somewhere via you agreeing to a license agree (extract it with jav xvf jarname.jar and check the README it contains).
For any JAR file on your CLASSPATH in Eclipse, you can add a source attachment to it to point to its source code. The easiest thing to do is bring up the Package Explorer view. Underneath your project, you should see an item for your Java Runtime Environment (JRE) (mine is called "JRE System Library [JavaSE-1.6]"). Click on the expansion arrow for that and you'll see a list of JARs.
Most all of the Java classes you'll care about viewing are stored in "classes.jar". Right-click on that JAR and select "Properties". In the left hand menu, select "Java Source Attachment". On the right side, click "External Folder" and find the source code that you downloaded and installed and put that folder into the "Location path" field. Hit "Apply" and "OK".
Now you should be able to right click on any built-in Java class in your code and use the "Open Declaration" command or when debugging you will now step into the Java source.
It's a great capability to have. Enjoy!
HashSet is in JRE Package, so you can download JDK source and attach it into eclipse.
An other way, when you can not find out the source package, you can use JD-Decompiler
which has eclipse plugin to decompile your class, it work and show most like original source file.
Choosing a JDK instead of JRE for the runtime environment worked for me!
NOTE:Make sure you have a JDK installed and not only JRE before proceeding.
Remove the current system JRE library:
Right Click project -> properties -> Libraries -> Remove current JRE Library.
Add other installed library to your project:
In the current dialogue box, click "add library". by default JRE system library is selected, if not, select it and click next. now select "Alternate JRE" and click "Installed JRE". In the new dialogue box, click search and provide the path to your installed Java environments.
Finalize
Select an installed JDK, and click OK. Click FINISH and again OK to proceed.
Abdul,
The best way is as the others explained to download the sources and attach them in the eclipse.
The EASIEST way would be installing the java decompiler (JAD). Take a look at http://jadclipse.sourceforge.net/install.html. Its explained there in 4 super simple steps :)
How do you install the source for the java libraries in Eclipse?
This happens automatically if you set up a JDK rather than a JRE.
Normally, when you start eclipse, it sets up the JRE that was used to start eclipse. You'll usually want to override this with a JDK so you get the source. To do this:
First, make sure you have a JDK installed (and not just a JRE)
Start eclipse
Go to Window->Preferences->Java->Installed JREs
Press Add...
Choose "Standard VM" and press "Next..."
Press "Directory...", select the JDK installation directory and press "Ok"
Press "Finish"
Make sure you check the box next to the new JDK
Press "Ok" to finish up
This will set up the source properly for you.
You can do it in the project preferences, but I find quite faster just to ctr+click over a object or class defined in the standard library and then "attach source" in the page that will gently inform you that there are no sources attached.
You then can point to the "src.zip" in your JDK distribution.
The way that I do it:
Prerequisite: you have the source downloaded. It comes with the JDK. (src.zip)
Open up a Java file
Ctrl + Click on a class name.
Click on the button that says 'Attach Source'
Locate the src.zip file. (Usually in the JDK install location)
Now you have the source installed!
WHat do you mean with java source? The java.lang package? Because there shouldn't be a need to "install" them. Creating a new Java Project ( any kind of Java Project) should be enough. Could you describe your problem in more detail?
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?
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
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.
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.
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.
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.
For ubuntu, install openjdk-6-source and use /usr/lib/jvm/java-6-openjdk/src.zip
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.
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.
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.
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.
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.
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.
#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).