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
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With