Java Reference
In-Depth Information
The above manifest file has one section with four attributes:
Manifest-Version
Created-By
Main-Class
Profile
There are two kinds of sections in a manifest file: the main section and the individual section. A blank line must
separate any two sections. Entries in the main section apply to the entire JAR file. Entries in the individual section
apply to a particular entry. An attribute in an individual section overrides the same attribute in the main section. An
individual entry starts with a “Name” attribute, whose value is the name of the entry in the JAR file and it is followed
by other attributes for that entry. For example, suppose you have a manifest file with the following contents:
Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: com.jdojo.chapter2.Welcome
Sealed: true
Name: book/data/
Sealed: false
Name: images/logo.bmp
Content-Type: image/bmp
The manifest file contains three sections: one main section and two individual sections. Note that there is a blank
line between the two sections. The first individual section indicates that the package book/data is not sealed. This
individual section attribute of "Sealed: false" will override the main section's attribute of "Sealed: true" . Another
individual section is for an entry called images/logo .bmp. It states that the content type of the entry is an image of
bmp type.
The jar command can create a default manifest file and add it to the JAR file. The default manifest file contains
only two attributes: Manifest-Version and Created-By . You can use the option M to tell the jar tool to omit the
default manifest file. The following command will create a test.jar file without adding a default manifest file:
jar cMf test.jar book/*.class
The jar command gives you an option to customize the contents of the manifest file. You can use the option m to
specify your file that has the contents for the manifest file. The jar command will read the name-value pairs from the
specified manifest file and add them to the MANIFEST.MF file. Suppose you have a file named manifest.txt with one
attribute entry in it. Make sure to add a new line at the end of the file. The file's contents are as follows:
Main-Class: com.jdojo.intro.Welcome
To add the Main-Class attribute value from manifest.txt file in a new test.jar file by including all class files in
the current working directory, you execute the following command:
jar cfm test.jar manifest.txt *.class
 
Search WWH ::




Custom Search