Wednesday 2 March 2016

JAR manifests

Note that the jar command automatically adds a directory called META-INF to our archive. The META-INF directory holds files describing the contents of the JAR file. It always contains at least one file: MANIFEST.MF. The MANIFEST.MF file can contain a “packing list” naming the files in the archive along with a user-definable set of attributes for each entry. The manifest is a text file containing a set of lines in the form keyword: value. The manifest is, by default, empty and contains only JAR file version information:

 Manifest-Version: 1.0  
 Created-By: 1.7.0_07 (Oracle Corporation)  
It is also possible to sign JAR files with a digital signature. When you do this, digest (checksum) information is added to the manifest for each archived item (as shown next) and the META-INF directory holds digital signature files for items in the archive.
 Name: com/oreilly/Test.class  
 SHA1-Digest: dF2GZt8G11dXY2p4olzzIc5RjP3=  
 ...  
You can add your own information to the manifest descriptions by specifying your own supplemental, manifest file when you create the archive. This is one possible place to store other simple kinds of attribute information about the files in the archive, perhaps version or authorship information. For example, we can create a file with the following keyword: value lines:
 Name: spaceblaster/images/planetoid.gif  
 RevisionNumber: 42.7  
 Artist-Temperament: moody  
To add this information to the manifest in our archive, place it in a file called myManifest. mf and give the following jar command:
 % jar -cvmf myManifest.mf spaceblaster.jar spaceblaster  
We included an additional option, m, which specifies that jar should read additional manifest information from the file given on the command line. How does jar know which file is which? Because m is before f, it expects to find the manifest information before the name of the JAR file it will create. If you think that’s awkward, you’re right; get the names in the wrong order, and jar does the wrong thing. An application can get this manifest information from a JAR file using the java.util.jar.Manifest class. We’ll see more examples of adding information to the JAR manifest. The JavaBeans APIs use manifest information to designate which classes are “beans” using a Java-Bean attribute. This information is used by IDEs that work with JavaBeans.

0 comments:

Post a Comment