使用 JDK 和/或 JRE 提供的工具,是否可以查看给定 JAR 的 Manifest 文件?

发布于 2024-07-27 05:42:18 字数 118 浏览 2 评论 0原文

我能够读取 Java 代码中的 Manifest 文件,但我还想知道是否可能,如果可能,如何从命令行打开 JAR 文件并查看其 Manifest.MF 文件,或者至少能够指定 Manifest.MF 文件的属性并查看其值。

I'm able to read the Manifest file inside of my Java code, but I would also like to know if it's possible, and if it is, how to open up a JAR file from the command line and view its Manifest.MF file, or at the very least be able to specify a property of the Manifest.MF file and view it's value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

み零 2024-08-03 05:42:18

来自此处 可以从 jar 文件中提取选定的条目。 例如,如果您只想查看meta-inf/manifest.mf 文件,您可以

C:\Sun\AppServer\lib>jar xvf j2ee.jar META-INF/MANIFEST.MF
inflated: META-INF/MANIFEST.MF

或者使用反斜杠而不是正斜杠:

C:\Sun\AppServer\lib>jar xvf j2ee.jar META-INF\MANIFEST.MF
inflated: META-INF/MANIFEST.MF

条目名称区分大小写,因此以下内容不会提取任何内容:

 C:\Sun\AppServer\lib>jar xvf j2ee.jar meta-inf/manifest.mf

当然,您始终可以双击该条目以在 WinZip、fileroller 或其他工具中查看它。

From here:

You can extract selected entries from a jar file. For instance, if you only want to view the meta-inf/manifest.mf file, you can

C:\Sun\AppServer\lib>jar xvf j2ee.jar META-INF/MANIFEST.MF
inflated: META-INF/MANIFEST.MF

Or using a backslash instead of a forward slash:

C:\Sun\AppServer\lib>jar xvf j2ee.jar META-INF\MANIFEST.MF
inflated: META-INF/MANIFEST.MF

The entry names are case sensitive, and so the following will not extract anything:

 C:\Sun\AppServer\lib>jar xvf j2ee.jar meta-inf/manifest.mf

Of course, you can always double-click the entry to view it in WinZip, fileroller, or other tools.

像这样的东西应该有效:

jar -xf <jarfile.jar> META-INF/MANIFEST.MF

Something like this should work:

jar -xf <jarfile.jar> META-INF/MANIFEST.MF
乖乖哒 2024-08-03 05:42:18

看起来 unzip 命令会对您有所帮助——它在大多数 Un*x 变体上都可用,并且如果您使用的是 Windows,它也是 cygwin 的一部分。 unzip -qc *jar-file* META-INF/MANIFEST.MF 会将清单内容转储到控制台。

it looks like the unzip command will help you -- it's available on most Un*x variants and is part of cygwin as well, if you are on Windows. unzip -qc *jar-file* META-INF/MANIFEST.MF will dump the contents of the manifest to the console.

美人骨 2024-08-03 05:42:18

JDK 提供的 jar 可执行文件的工作方式与 tar 在 Linux 上的工作方式相同。

例如 jar xvf .... 请参阅 jar 选项。

the jar executable provided by JDK works the same way tar works on linux.

jar xvf for example .... See jar options.

洛阳烟雨空心柳 2024-08-03 05:42:18

运行时的属性不应在清单中定义,它们应在遵循 Java 属性样式的单独配置文件中定义。 假设您出于某种原因在运行时检查清单。

但如果您需要:

jar xvf somejar.jar META-INF/MANIFEST.MF

将夸大清单以满足您的观看乐趣。

Properties for runtime should not be defined in the manifest, they should be defined in separated config files that follow the Java Properties style. Assuming you are checking the manifest at runtime for whatever reason.

But if you need to:

jar xvf somejar.jar META-INF/MANIFEST.MF

will inflate the manifest for your viewing pleasure.

花想c 2024-08-03 05:42:18

没有办法使用 jar 命令; 最接近的是使用 -tf 来显示 META-INF/MANIFEST.MF 文件或 -xf 是否存在来提取它。

解决方法:

  • 您可以编写自己的类来执行此操作
  • 您可以使用任何 ZIP 文件查看器来提取内容 - 许多人会将存档中的文件内容写入到 stdout,以便可以将其通过管道传输到另一个命令中(请记住, jar 文件只是 zip 文件的具体用法)

There is not a way with the jar command; the closest you can get is to use -tf to show the presence or absence of a META-INF/MANIFEST.MF file or -xf to extract it.

Work-arounds:

  • You could write your own class to do this
  • You could use any ZIP file viewer to extract the contents - many will write the contents of a file in an archive to stdout so that it can be piped into another command (remember, jar files are just a specific usage of zip files)
秉烛思 2024-08-03 05:42:18

你可以使用 vi 来实现这一点。 如果您想确保不更改文件,请使用 -R 开关(只读)打开。 例如:

vi -R sample-1.0.0-SNAPSHOT.jar

您可以使用向上/向下箭头导航到 zip 文件,或使用 / 进行搜索 例如:

/MANIFEST.MF

要退出,请输入以下序列

:q <Enter>

You can just use vi for that. If you want to make sure that you don't change the file, open with with -R switch (for readonly). e.g:

vi -R sample-1.0.0-SNAPSHOT.jar

You can navigate to the zip file with the up/down arrow, or search with / e.g.:

/MANIFEST.MF

To exit type the following sequence

:q <Enter>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文