使用JDK和/或JRE提供的工具,有没有办法查看给定JAR的Manifest文件?

时间:2023-01-18 09:03:48

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.

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

7 个解决方案

#1


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

您可以从jar文件中提取所选条目。例如,如果您只想查看meta-inf / manifest.mf文件,则可以

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.

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

#2


Something like this should work:

这样的事情应该有效:

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

#3


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.

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

#4


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

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

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

jar xvf例如....查看jar选项。

#5


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.

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

But if you need to:

但如果你需要:

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

will inflate the manifest for your viewing pleasure.

将为您的观看乐趣充气。

#6


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.

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

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)
  • 您可以使用任何ZIP文件查看器来提取内容 - 许多人会将存档中文件的内容写入stdout,以便可以将其传送到另一个命令(请记住,jar文件只是zip文件的特定用法)

#7


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开关打开(对于readonly)。例如:

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.:

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

/MANIFEST.MF

To exit type the following sequence

要退出键入以下序列

:q <Enter>

#1


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

您可以从jar文件中提取所选条目。例如,如果您只想查看meta-inf / manifest.mf文件,则可以

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.

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

#2


Something like this should work:

这样的事情应该有效:

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

#3


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.

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

#4


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

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

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

jar xvf例如....查看jar选项。

#5


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.

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

But if you need to:

但如果你需要:

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

will inflate the manifest for your viewing pleasure.

将为您的观看乐趣充气。

#6


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.

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

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)
  • 您可以使用任何ZIP文件查看器来提取内容 - 许多人会将存档中文件的内容写入stdout,以便可以将其传送到另一个命令(请记住,jar文件只是zip文件的特定用法)

#7


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开关打开(对于readonly)。例如:

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.:

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

/MANIFEST.MF

To exit type the following sequence

要退出键入以下序列

:q <Enter>