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.
我遇到了一个对我来说绝对新鲜的有趣问题。正如我突然发现的那样,Jar规范说,包括在内,META-INF和MANIFEST.MF必须是* .jar包的第一和第二个条目,而不仅仅是归档中的目录和文件。
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?
我正在使用Java框架非常注意这个要求而不是那么冗长。如何在jar中检查META-INF和MANIFEST.MF是否正确订购?
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!
更新:许多罐子都是第三方,其中有很多。我无法在记事本,excel,hexeditor,photoshop或任何寻找字节序列的东西中打开这些罐子。我需要命令行工具。谢谢!
UPDATE 2: Here is the reason why I'm asking this question: http://www.mail-archive.com/dev@felix.apache.org/msg17097.html
更新2:以下是我提出这个问题的原因:http://www.mail-archive.com/dev@felix.apache.org/msg17097.html
3 个解决方案
#1
5
The following command will list the contents of a JAR in order:
以下命令将按顺序列出JAR的内容:
jar tf foo.jar
Note that there is no actual requirement in the JAR specification for META-INF/MANIFEST.MF
to appear first. However JARs built by the jar
tool (supplied with the JDK) do have the manifest first, and therefore it has become a convention.
请注意,首先出现META-INF / MANIFEST.MF的JAR规范中没有实际要求。但是,由jar工具(随JDK提供)构建的JAR首先具有清单,因此它已成为惯例。
#2
2
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.
带有JDK的jar工具会自动添加它们,所以不应该做任何事情。如果你真的想检查,得到一个十六进制编辑器,并在任何其他文件名之前查找字符串'META-INF'和'MANIFEST.MF'。
#3
1
To fix the broken JARs:
要修复损坏的JAR:
$ mkdir foo
$ cd foo
$ jar xvf ../broken.jar
$ mv META-INF/MANIFEST.MF /tmp/mymanifest
$ jar cvfm fixed.jar /tmp/mymanifest .
SEE: MANIFEST.MF must be the first resource in a jar file – here’s how to fix broken jars
请参阅:MANIFEST.MF必须是jar文件中的第一个资源 - 以下是如何修复损坏的jar
#1
5
The following command will list the contents of a JAR in order:
以下命令将按顺序列出JAR的内容:
jar tf foo.jar
Note that there is no actual requirement in the JAR specification for META-INF/MANIFEST.MF
to appear first. However JARs built by the jar
tool (supplied with the JDK) do have the manifest first, and therefore it has become a convention.
请注意,首先出现META-INF / MANIFEST.MF的JAR规范中没有实际要求。但是,由jar工具(随JDK提供)构建的JAR首先具有清单,因此它已成为惯例。
#2
2
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.
带有JDK的jar工具会自动添加它们,所以不应该做任何事情。如果你真的想检查,得到一个十六进制编辑器,并在任何其他文件名之前查找字符串'META-INF'和'MANIFEST.MF'。
#3
1
To fix the broken JARs:
要修复损坏的JAR:
$ mkdir foo
$ cd foo
$ jar xvf ../broken.jar
$ mv META-INF/MANIFEST.MF /tmp/mymanifest
$ jar cvfm fixed.jar /tmp/mymanifest .
SEE: MANIFEST.MF must be the first resource in a jar file – here’s how to fix broken jars
请参阅:MANIFEST.MF必须是jar文件中的第一个资源 - 以下是如何修复损坏的jar