How can I browse the source code in a jar file con

2019-03-30 16:30发布

I have a jar file that contains source code. How can I browse this source code in Eclipse?

At the moment, my Eclipse opens the jar file in a Text Editor, and it isn't that helpful.

When I look in the preferences "General" > "Editors" > "File Associations" I have no associations for *.jar and if I look in the available "Editors" I can't find anyone that seem to be a good fit for jar files.

How can I browse the source code in a jar file using Eclipse? Is there any Editor I should configure for jar files?

3条回答
唯我独甜
2楼-- · 2019-03-30 16:53

Extract the jar in some source directory (it's a zip file), and create a project with this directory as source.

Or, if this source jar file contains the sources of a classes jar file that is used as a library in your Eclipse project, just right-click on this jar file, select "Properties", then "Java Source Attachment", then "External File", and select the source jar file. Then each time you browse a class from this classes jar file, Eclipse will automatically show you its source code.

查看更多
女痞
3楼-- · 2019-03-30 17:00

If you have the jar added to a project's classpath, you can view its source by:

  1. Expanding Referenced Libraries in the Package Explorer view
  2. Expand the jar you're looking at
  3. Double clicking on a .class file

You need both the .class and .java file in the jar to view source, though.
If you have only the .java file, the class won't appear at all.
If you have only the .class file, the class will appear as bytecode.

Example:

screenshot of eclipse with referenced jar expanded

查看更多
虎瘦雄心在
4楼-- · 2019-03-30 17:14

If you want just to open jar o war files (and search or browse scripting code), install the Eclipse plugin called "Eclipse zip editor", from eclipse marketplace. Just in case it's the website to drag and drop to eclipse

enter image description here

查看更多
登录 后发表回答