How do I verify the order of MANIFEST.MF within ja

2019-04-07 10:50发布

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

3条回答
Ridiculous、
2楼-- · 2019-04-07 10:56

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-04-07 10:58

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.

查看更多
\"骚年 ilove
4楼-- · 2019-04-07 11:06

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

查看更多
登录 后发表回答