Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 506
andbi Avatar asked Jan 18 '11 18:01

andbi


People also ask

How do I view the manifest of a JAR file?

The manifest file is named MANIFEST. MF and is located under the META-INF directory in the JAR. It's simply a list of key and value pairs, called headers or attributes, grouped into sections.

How do I edit a manifest MF in a JAR file?

To modify the manifest, you must first prepare a text file containing the information you wish to add to the manifest. You then use the Jar tool's m option to add the information in your file to the manifest. Warning: The text file from which you are creating the manifest must end with a new line or carriage return.

What is manifest MF in JAR?

The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to serve a variety of purposes.

How can I view the contents of a JAR file without extracting it?

List Files. List all the files inside the JAR without extracting it. This can be done using either command jar , unzip or vim . Using unzip command in normal mode: list ( -l ) archive files in short format.


3 Answers

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.

like image 164
Neil Bartlett Avatar answered Sep 29 '22 21:09

Neil Bartlett


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.

like image 21
Peter C Avatar answered Sep 29 '22 23:09

Peter C


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

like image 42
Stijn de Witt Avatar answered Sep 29 '22 22:09

Stijn de Witt