How can I browse the source code in a jar file containing source code in Eclipse?

扶醉桌前 提交于 2020-01-01 06:35:08

问题


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?


回答1:


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.




回答2:


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:




回答3:


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



来源:https://stackoverflow.com/questions/8042496/how-can-i-browse-the-source-code-in-a-jar-file-containing-source-code-in-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!