如何验证 jar 内 MANIFEST.MF 的顺序?
我遇到了一个有趣的问题,这对我来说绝对是新的。正如我突然发现的,Jar 规范规定,要包含 META-INF
和 MANIFEST.MF
必须是 *.jar< 的第一个和第二个条目/code> 包,而不仅仅是存档中的目录和文件。
我正在使用 Java 框架,非常注意这一要求,并且没有那么冗长。如何检查 META-INF
和 MANIFEST.MF
在 jar 内是否正确排序?
更新: 很多jar都是第三方的,而且数量也很多。我无法在记事本、Excel、十六进制编辑器、Photoshop 或任何寻找字节序列的工具中打开这些罐子。我需要命令行工具。谢谢!
更新2: 这就是我问这个问题的原因: http://www.mail-archive.com/[电子邮件受保护]/msg17097.html
I've run into interesting problem which is absolutely new to me. As I've suddenly discovered, Jar specification says that, being included, META-INF
and MANIFEST.MF
must be first and second entries of *.jar
package and not just directory and file within archive.
I'm working with Java framework being very watchful about this requirement and not as much verbose. How do I check that META-INF
and MANIFEST.MF
are properly ordered within jar?
UPDATE:
Many of jars are third-party, and there are many of them. I'm not able to open these jars in notepad, excel, hexeditor, photoshop or whatever looking for byte sequences. I need command-line tool. Thanks!
UPDATE 2:
Here is the reason why I'm asking this question:
http://www.mail-archive.com/[email protected]/msg17097.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下命令将按顺序列出 JAR 的内容:
请注意,JAR 规范中并没有实际要求
META-INF/MANIFEST.MF
首先出现。然而,由jar
工具(随 JDK 提供)构建的 JAR 确实首先具有清单,因此它已成为一种约定。The following command will list the contents of a JAR in order:
Note that there is no actual requirement in the JAR specification for
META-INF/MANIFEST.MF
to appear first. However JARs built by thejar
tool (supplied with the JDK) do have the manifest first, and therefore it has become a convention.JDK 的 jar 工具会首先自动添加它们,因此您无需执行任何操作。如果您确实想检查,请使用十六进制编辑器并在任何其他文件名之前查找字符串“META-INF”和“MANIFEST.MF”。
The jar tool with the JDK automatically adds them first, so there shouldn't be anything you have to do. If you really want to check, get a hex editor and look for the strings 'META-INF' and 'MANIFEST.MF' before any other file names.
要修复损坏的 JAR:
请参阅:MANIFEST.MF 必须是 jar 文件中的第一个资源 - 以下是修复损坏的 jar 的方法
To fix the broken JARs:
SEE: MANIFEST.MF must be the first resource in a jar file – here’s how to fix broken jars