JAR File Format and 'jar' Tool
Part:
1
2
3
4
5
(Continued from previous part...)
What Is "manifest"?
"manifest" in a JAR file is a file named as META-INF/MANIFEST.MF. It contains attributes
about the JAR file and its contents.
Attributes in "manifest" are recorded as a list of name-value pairs in the form of "name: value\n".
The list is divided into a main section for package-level attributes and multiple sub sections
for entry-level attributes. Note that each attribute must be ended with a new line character.
The main section may contain only the package level attributes like:
- Manifest-Version
- Created-By
- Main-Class
- Class-Path
- Implementation-Vendor
- Implementation-URL
Sub sections are optional. They are used to provide entry-level attributes with one section
per entry. A sub sections must be preceded with a blank line and started with a "Name" attribute
to associate this section with a content entry in the JAR file. Example of entry-level attributes
are:
Adding "manifest" to JAR Files
There are two ways to add "manifest" to a JAR file.
1. Adding "manifest" through "jar" command line. Store all your manifest attributes in a file. And specify this file
in the "jar" command line with the "m" option:
jar c[v0]mf manifest jarfile inputfiles
For example, I created my own manifest file called manifest.txt with one attribute in it:
Main-Class: Hello
Remember to press the <Enter> key at the end of the attribute. This will insert a new line character (\n)
to terminate the attribute.
Here is how I added my manifest to a JAR file with the "m" option:
>jar cvmf manifest.txt hello.jar Hello.class
added manifest
adding: Hello.class(in = 416) (out= 285)(deflated 31%)
>jar xvf hello.jar
created: META-INF/
extracted: META-INF/MANIFEST.MF
extracted: Hello.class
>type META-INF\MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.4.2 (Sun Microsystems Inc.)
Main-Class: Hello
As you can see that "jar" command copied the attribute from my manifest file to the end of the auto-generated
MANIFEST.MF file.
2. Adding "manifest" through META-INF/MANIFEST.MF file. Create META-INF/MANIFEST.MF as a text file. Enter all your
manifest attributes in this file. And include META-INF/MANIFEST.MF as an input file to JAR file.
For example, I created my own META-INF/MANIFEST.MF with a text editor as:
Manifest-Version: 3.3
Created-By: Herong Yang
Main-Class: Hello
Here is how I added my manifest to a JAR file with the "M" option:
>jar cvMf tutu.jar Hello.class META-INF
adding: Hello.class(in = 416) (out= 285)(deflated 31%)
adding: META-INF/(in = 0) (out= 0)(stored 0%)
adding: META-INF/MANIFEST.MF(in = 19) (out= 21)(deflated -10%)
C:\herong\jtool_20051119\src>jar tf tutu.jar
Hello.class
META-INF/
META-INF/MANIFEST.MF
Note that:
- The "M" option stops "jar" to auto-generate the META-INF/MANIFEST.MF file.
- When MANIFEST.MF is included as an input file, it was compressed. This is different than the auto-generated
version, which was not compressed at all.
(Continued on next part...)
Part:
1
2
3
4
5
|