如何将 Java 库的内容转储到控制台?
是否有工具可以将库或 JAR 文件的内容转储到控制台?
我正在寻找 DUMPBIN /SYMBOLS
的 Java 对应项,它适用于 Windows 本机模式库。对于 C# 和 .NET 的其余部分,有很多可视化工具,例如 .NET Reflector 以及 Visual Studio 中内置的对象浏览器。总而言之,我更喜欢命令行工具,但我会感激任何有用的东西:)
(我刚刚开始在 Windows 上使用 Java 和 Scala。)
Is there a tool for dumping the contents of a library or JAR file to the console?
I'm looking for the Java counterpart of DUMPBIN /SYMBOLS
, which works on Windows native-mode libaries. With C# and the rest of .NET, there are a bunch of visual tools like .NET Reflector and the object browsers built into Visual Studio. All-in-all, I prefer command-line tools, but I will be grateful anything that works :)
(I'm just getting started with Java and Scala on Windows.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您要查找的命令是:
jar tf
The command you're looking for is:
jar tf <jarfilename>
您可以解压 JAR 文件 (
jar xf my.jar
) 以查看内容;如果您想在代码中执行此操作,java.util.jar
中提供了用于处理 JAR 文件的工具。或者,如果您知道包层次结构的一部分,则可以在 Scala REPL 中键入它的一部分 并点击选项卡以获取有效完成的列表。例如:
然而,如果没有 API 文档,就很难弄清楚如何使用这些东西。您的第一步几乎总是应该尝试查找文档并查看它们。
You can unpack a JAR file (
jar xf my.jar
) to see the contents; if you want to do this within your code, there are tools injava.util.jar
for working with JAR fileS.Alternatively, if you know part of the package hierarchy, you can type part of it in the Scala REPL and hit tab to get a list of valid completions. For example:
However, it's awfully hard to figure out how to use things without API documentation. Your first step should almost always be to try to find the documentation and look at them instead.
如果您知道类名:
您还可以对其进行“脚本化”,以便它迭代 jar 文件中的所有类并为每个类运行 javap
If you know the class name:
Also you can "script-ize" it so that it iterates through all the classes in the jar file and run javap for each one
另请注意,JAR 文件只是一个压缩文件,因此任何 ZIP 实用程序都会做。大多数 IDE 都提供探索您添加到项目中的 JAR 库的功能 (Eclipse例如)。
Also note that a JAR file is merely just a zipped file so any ZIP utility would do. And most IDEs offer to explore inside the JAR libraries you add to a project (Eclipse for instance).
如前所述,JAR 文件是 ZIP 文件,可以用相同的方式提取。
要浏览 JAR 文件中的类,我建议您使用 IDE。将 JAR 文件作为库依赖项添加到您的项目中,然后您应该能够浏览类和方法。
获取 JAR 文件的源代码怎么样(如果可能的话)?
As mentioned, JAR files are ZIP files and can be extracted in the same way.
To browse the classes inside a JAR file, I recommend you to use an IDE. Add the JAR file as a library dependency to your project, and then you should be able to browse through the classes and methods.
How about obtaining the source code for the JAR file (if that's possible)?