Java 查看 .jar 文件的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/320510/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 13:07:28  来源:igfitidea点击:

Viewing contents of a .jar file

javajarviewer

提问by Dani

What would be the easiest way to view classes, methods, properties, etc. inside a jar file? I'm looking for something equivalent to the very useful Lutz Roeder .NET Reflector - for Java

在 jar 文件中查看类、方法、属性等的最简单方法是什么?我正在寻找与非常有用的Lutz Roeder .NET Reflector相当的东西- 用于 Java

回答by PhiLho

I usually open them with 7-Zip... It allows at least to see packages and classes and resources.
Should I need to see methods or fields, I would use Jad but of course, it is better to rely on (good) JavaDoc...

我通常用 7-Zip 打开它们...它至少可以看到包、类和资源。
如果我需要查看方法或字段,我会使用 Jad 但当然,最好依赖(好的)JavaDoc ...

Now, somewhere on SO was mentioned some Eclipse plug-ins, to find in which jar file a class is located, perhaps they can do more (ie. what you requested).

现在,SO 上的某个地方提到了一些 Eclipse 插件,以查找类位于哪个 jar 文件中,也许他们可以做更多(即您要求的)。

[EDIT] Reference to SO thread. Not what is asked, but somehow related, thus useful: Java: How do I know which jar file to use given a class name?

[编辑] 对 SO 线程的引用。不是问什么,而是以某种方式相关,因此很有用:Java:我如何知道给定类名要使用哪个 jar 文件?

回答by M.N

Use WinRar. It will open the folder structure for you in intact manner. Also allows in-archive editing, while preserving paths.

使用 WinRar。它将以完整的方式为您打开文件夹结构。还允许存档内编辑,同时保留路径。

Afterall, a JAR file is a ZIP archive only.

毕竟,JAR 文件只是一个 ZIP 档案。

回答by Jeroen Heijmans

Well, a jar-file is just a zip-file, so if you unzip it (with your favorite unzipping utility), you get all the files inside.

嗯,jar 文件只是一个 zip 文件,所以如果你解压它(用你最喜欢的解压工具),你会得到里面的所有文件。

If you want to look inside the class files to see the methods, you'll need a tool for that. As PhiLho mentions, Eclipse is able to do that (by default), and I would think most Java IDEs are capable of that.

如果您想查看类文件内部以查看方法,则需要一个工具。正如 PhiLho 所提到的,Eclipse 能够做到这一点(默认情况下),我认为大多数 Java IDE 都能够做到这一点。

回答by Dan Dyer

You could try JarSpy. There is an IDEA plugin version of it that I use.

你可以试试JarSpy。我使用了它的 IDEA 插件版本。

回答by Tom Hawtin - tackline

Using the JDK, jar -tfwill list the files in the jar. javapwill give you more details from a particular class file.

使用 JDK,jar -tf将列出 jar 中的文件。javap将从特定的类文件中为您提供更多详细信息。

回答by audiodude

I prefer JAR Browser, it has a simple interface where you can browse multiple JARs, and search for a specific class across multiple JARs simultaneously.

我更喜欢JAR Browser,它有一个简单的界面,您可以在其中浏览多个 JAR,并同时在多个 JAR 中搜索特定类。

回答by erickson

Jad is klunky and no longer maintained. I've switched to "Java Decompiler", which has a slick UI and support for new language features.

Jad 很笨拙,不再维护。我已经切换到“Java Decompiler”,它有一个漂亮的用户界面和对新语言特性的支持。

Every decompiler I've used, though, runs into code it doesn't successfully decompile. For those, it helps to understand the disassembled Java byte code produced by the standard JDK tool, javap.

但是,我使用过的每个反编译器都会遇到无法成功反编译的代码。对于那些,它有助于理解标准 JDK 工具javap生成的反汇编 Java 字节码。

回答by Dennis C

Eclipse 3.4 JDT

Eclipse 3.4 JDT

It is not the quickest way because you have to drag it into your eclipse first. But you will have full java class browsing, even with decompile enabled.

这不是最快的方法,因为你必须先把它拖到你的日食中。但是您将拥有完整的 Java 类浏览,即使启用了反编译。

回答by John T

You can open them with most decompression utilities these days, then just get something like DJ Java Decompilerif you want to view the source.

如今,您可以使用大多数解压实用程序打开它们,然后如果您想查看源代码,就可以使用DJ Java Decompiler 之类的东西。

回答by TREE

Your IDE should also support this. My IDE (SlickeEdit) calls it a "tag library." Simply add a tag library for the jar file, and you should be able to browse the classes and methods in a hierarchical manner.

您的 IDE 也应该支持这一点。我的 IDE (SlickeEdit) 称它为“标签库”。只需为 jar 文件添加一个标记库,您应该能够以分层方式浏览类和方法。