开发者

How do I verify the order of MANIFEST.MF within jar?

开发者 https://www.devze.com 2023-02-05 13:52 出处:网络
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 s

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/dev@felix.apache.org/msg17097.html


The following command will list the contents of a JAR in order:

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.


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.


To fix the broken JARs:

$ 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

0

精彩评论

暂无评论...
验证码 换一张
取 消