1

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?

MichalB
  • 3,281
  • 6
  • 32
  • 46
  • 2
    two ways here. [1] find the source jar (usually available for all open source jars) or [2] decompile the classes (may need some extra work) – Leo Jul 08 '14 at 05:12

4 Answers4

3

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

Ruben
  • 1,427
  • 3
  • 17
  • 25
2

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.
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
2

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.

Atul Sharma
  • 718
  • 4
  • 11
0

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

Community
  • 1
  • 1