Browse JDK Source Code in Eclipse Like GrepCode - java

I like the way you can browse the source code of a library in GrepCode. Is there any way I can do the same in Eclipse?
I know that I can open the declaration of a class and look through it, but there seems to be no way I can search for something (a method, for example) in the Declaration window.
What I am really looking for is a way to browse the source code of the standard library just like I browse the source code of a class I am writing. It doesn't necessarily have to be the source that ships along with my JDK; I am happy to look at some other version as well.
What would be the best way to achieve this? Will I have to download OpenJDK and add it as a project in Eclipse?

You can install Java Decompiler plugin for Eclipse, such as JD-Eclipse
You could also use the src.zip file that ships alongside Oracle's JDK (located for example at something similar to C:\Program Files\Java\jdk{version} in Windows) and load it on Eclipse build path as a library (src.zip contains sources files for the java., javax. and some org.* packages, but not for com.sun.* packages)
Or you could download the whole bundle of source code for JDK at http://download.java.net/openjdk/jdk6/ (for JDK 1.6) and do the same

I think one of the good alternative for what you are looking for is zGrepCode. It allows you to browse Java Open Source projects as you are doing it in Eclipse by providing interlinking.
http://zgrepcode.com
Here is the place I found about this wonderful free tool.
https://dzone.com/articles/grepcode-is-down-whats-next?fromrel=true

Actually I just went with the Search feature in Eclipse. Since I wanted to look at the source code for classes in the JRE libraries, I just do Search --> Java and select the appropriate options (see the attached screenshot).
I would think that this Search feature could also be used to search in the libraries included in your build path too.

Pretty sure that m2eclipse allows source browsing, see: Get source jar files attached to Eclipse for Maven-managed dependencies
Intellij also has a maven plugin available that allows browsing.

Related

How to include Javadoc in a library JAR?

I'm currently trying to write my first own library. It's just for testing, I want to find out how libraries are written, compiled, distributed and used in order to prepare for some upcoming personal projects.
Yet, what really causes me to wonder, is why exactly my Javadoc isn't compiled with the Library. I know that comments and annotations are not compiled, but for example the JDK (which is basically a huge library) comes with a working doc as well.
I've tried to compile a JAR (libraries aree normally JARs, right?) from not the compile output, but the sources (so I had a JAR of .java files), but this failed to be included in IntelliJ. I could add it as an external library, but neither did it show up in my explorer, not could I import or use any of my classes.
I know there must be a mistake somewhere here, all libraries I've ver used, whether it was Java, C# or whatever else always came with a working documentation (IntelliJ shold show that on mouse hover), and I'd like to know how to correctly build a library that I can share with a team partner, so he just needs to download it, add it as a library in IntelliJ and has all the functionality, but also the documentation.
Thanks to everyone in advance!
Because it isn't needed, and would bloat the file size of the executable. If you have a library in C or C++, the documentation may be bundled in a zip file, but you won't find it in the compiled .so or .dll. One just holds the binary and resources needed for the project. The .jar is equivalent of that- it's the compiled output. Documentation is hosted/downloaded separately.
When you download the JDK, you're not just downloading a giant .jar. It includes other things, like documentation in the download.
I'd like to know how to correctly build a library that I can share with a team partner, so he just needs to download it, add it as a library in IntelliJ and has all the functionality, but also the documentation.
The short answer is that you provide your team partners with your project source code as well as the binaries. They then can configure their IDE (Intellij, NetBeans, Eclipse, whatever) with the location of the source code and the IDE will be able to extract the javadoc comments on the fly and render them as requested.
Sharing the source code also has the additional benefit that your partners can debug their (and your) code better. By themselves, javadocs are rarely sufficient for debugging complicated problems.
Alright, if everyone ever has this probelm again, here's a complete tutorial:
As #Gabe Sechan already said, the Doc is not compiled into the JAR for some valid reasons. Instead, I recommend you to add the following to your JAR:
module compilation output
content of "src" directory / alternatively: module sources
Build --> Artifacts --> All Artifacts.
Now, if you add your library JAR into a project, it will show "Classes" and "Sources" in the right tab, as IntelliJ automatically recognizes you've bundled both into the JAR.
Now, IntelliJ should show your documentation, as it lives within the source files.
If, for some reason, IntelliJ switches from its "fancy" documentation popup to unformatted plain text, proceed as follows:
Navigate to File -> Settings -> Advanced Settings, and in the 5th block, where it says "Documentation Components", just tick everything you find. That's gonna fix it.
Thanks to Gabe Sechan again, your answer helped me to understand what won't work, and finally I've found a way to make it work myself.

How do I enable showing fuction explanation on eclipse? [duplicate]

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).

Find text in decompiled jar files with Jetbrains IDES

I'm with Jetbrains IntelliJ (or Android Studio if you prefer), and my project is built with gradle and some external java libraries from my company namespace. Thing is that is difficult to navigate trough classes as i cannot search text into the .jar files or resolve usages.
Do you have any idea of how to do this?, is there a plugin or something? a trick maybe?
Many thanks.
IntelliJ IDEA (as of 2017.2 or newer) knows how to decompile JAR files with no source attached, that is when you are in debug mode and you jump into the implementation. However this will not allow you full text search (such as looking for usages).
If it's just 1-2 JARs that you care for browsing, you may manually edit your Module properties in IntelliJ and add the source JAR files (that you need to download from your Library's website along with the binary JARs).
Another option is to use Maven, and have it download the source alongside with the binaries from the public Maven repository (if we're talking about open source libraries).
Yet another option, in an enterprise setting someone typically sets up an Artifactory (for instance https://www.jfrog.com/artifactory/ ), which is source for all the libraries and their source code.
If you use some up-to-date build script (for example Gradle), you can build an IntelliJ project with all the sources already linked in.
Hope this helps!
There is no easy way to do it. The only way to search for anything in library code is to attach source. The attached source can be code that you decompiled yourself, but IDE won't do it for you (but I think someone can write plugin that decompiles the whole library and attaches the decompiled source). So I guess that could be the "trick" you need to do.
Why is it impossible? I didn't write the IDE so I can't be sure why. But most likely the problem with finding text in jar files with no source attached, is that the text representation depends on the decompiler. There is no "best" way to decompile given class. Sometimes the decompilation may be even impossible (for example bytecode with a lot of goto/conditional jump instructions that don't nicely translate into loop/conditional constructs). In such cases decompilers can do anything from throwing an exception, putting raw bytecode, to just putting goto statements in the java code to at least show what the code is doing.
The only way that would allow to search in decompiled code (assuming you can't just download the code somewhere), would be to decompile it yourself (for example using the fernflower decompile, which is also used by intellij idea) and attach the decompiled source code.
While the above argument doesn't apply when finding usages of methods/fields, it's still not allowed, most likely because the IDE analyzes the source code to find usages, instead of analyzing the bytecode (compiled code).

See Javadocs for basic classes in Intellij

Is there a way to see/attach the Javadocs and/or source code for basic classes (like String) in IntelliJ?
I'm using IntelliJ Community Edition 11.1
When you add new JSDK, sources are configured automatically:
If your JDK installation is missing sources, you will need to download and configure them manually. Mac users should refer to this answer.
When you have sources attached to the JSDK configuration, navigating to the class will open source code instead of decompiled stub and you can also use View | Quick Documentation based on the javadoc in the source files.
Have a look at productivity tips:
http://www.jetbrains.com/idea/documentation/tips/index.html

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

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).

Categories