MichalB
MichalB

Reputation: 3341

How to display the source code of an external JAR in Eclipse?

In Eclipse, I just imported an external JAR. Viewing any of the classes in the Package Explorer will instead of showing a source code open a Class File Editor with saying "Source not found". The folder of the JAR I have downloaded, however, has only JAR, no lib, no src, no docs.

Is there still a way how to view/generate a view the source code so then I can view it in Eclipse properly?

Upvotes: 1

Views: 3946

Answers (4)

Nicola Baiocco
Nicola Baiocco

Reputation: 156

If possible I suggest you to use Maven for manage dependencies of your project, in most cases it did the trick for you. See: Get source JARs from Maven repository

Upvotes: 0

Atul Sharma
Atul Sharma

Reputation: 728

You cannot view the source form a .jar files as it contains binaries.Use a java decompiler instead to decompile the .class files and view their sources.

Upvotes: 2

Siddharth_Vyas
Siddharth_Vyas

Reputation: 10100

Try this :

  • Download java decompiler from http://jd.benow.ca/ and now double click on jd-gui and click on open file.
  • Then open .jar file from that folder.
  • Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name.

Upvotes: 2

Ruben
Ruben

Reputation: 1437

.jar files don't contain source code but are more like binary files for Java.

You can either get the source code from the projects page (if it is an OpenSource project of course)

An other possible way to view the source code of a .jar file is by using a decompiler (http://jd.benow.ca/; Also has a Eclipse plugin I think). This method can be very painful though when an obfuscator has been used by the developer who generated the .jar file.

Upvotes: 3

Related Questions