如何在 Eclipse 中浏览包含源代码的 jar 文件中的源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8042496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I browse the source code in a jar file containing source code in Eclipse?
提问by Jonas
I have a jar file that contains source code. How can I browse this source code in Eclipse?
我有一个包含源代码的 jar 文件。如何在 Eclipse 中浏览此源代码?
At the moment, my Eclipse opens the jar file in a Text Editor, and it isn't that helpful.
目前,我的 Eclipse 会在文本编辑器中打开 jar 文件,但并没有那么有用。
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.
当我查看首选项“常规”>“编辑器”>“文件关联”时,我没有任何关联*.jar
,如果我查看可用的“编辑器”,我找不到任何似乎适合 jar 文件的人。
How can I browse the source code in a jar file using Eclipse? Is there any Editor I should configure for jar files?
如何使用 Eclipse 浏览 jar 文件中的源代码?我应该为 jar 文件配置任何编辑器吗?
回答by Chris
If you have the jar added to a project's classpath, you can view its source by:
如果将 jar 添加到项目的类路径中,则可以通过以下方式查看其源代码:
- Expanding
Referenced Libraries
in thePackage Explorer
view - Expand the jar you're looking at
- Double clicking on a .class file
Referenced Libraries
在Package Explorer
视图中展开- 展开您正在查看的罐子
- 双击 .class 文件
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.
但是,您需要 jar 中的 .class 和 .java 文件才能查看源代码。
如果您只有 .java 文件,则该类根本不会出现。
如果您只有 .class 文件,则该类将显示为字节码。
Example:
例子:
回答by JB Nizet
Extract the jar in some source directory (it's a zip file), and create a project with this directory as source.
将 jar 解压缩到某个源目录中(它是一个 zip 文件),并以此目录作为源创建一个项目。
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.
或者,如果此源 jar 文件包含用作 Eclipse 项目中的库的类 jar 文件的源,只需右键单击此 jar 文件,选择“属性”,然后选择“Java 源附件”,然后选择“外部”文件”,然后选择源 jar 文件。然后每次从这个类 jar 文件浏览一个类时,Eclipse 将自动显示它的源代码。
回答by Edison Agurto
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
如果您只想打开 jar o war 文件(并搜索或浏览脚本代码),请从 eclipse 市场安装名为“Eclipse zip 编辑器”的 Eclipse 插件。以防万一是拖放到eclipse的 网站