The Manifest File

   

The first entry in any JAR file is a collection of meta-information about the archive. The JAR tool generates this meta-information automatically and stores it in a top-level directory named META-INF. This directory always contains what is known as the manifest file, META-INF/MANIFEST.MF (see Listing 25.3). Use the following command to extract the manifest file:

 C:\jdk1.3\demo\applets\TicTacToe>jar xvf ourtest.jar META-INF/MANIFEST.MF extracted: META-INF/MANIFEST.MF C:\jdk1.3\demo\applets\TicTacToe> 

Listing 25.3a shows the contents of the manifest file from ourtest.jar file.

Listing 25.3a Manifest File MANIFEST.MF of ourtest.jar
 Manifest-Version: 1.0 Created-By: 1.3.0 (Sun Microsystems Inc.) 

The manifest file that is created automatically by the JAR tool doesn't contain much information. There are many parameters that can be added to take advantage of special features of JAR files. The following list summaries the most important features:

  • Applications Bundled as JAR Files

  • Package Sealing

  • Package Versioning

  • Download Extensions

Applications Bundled as JAR Files

If you bundle your entire application as a JAR file, there has to be some way to indicate which class file contains the main method that is the entry point to your application. You can do this by putting the following line into the manifest file:

 Main-Class: classname 

classname is the fully qualified name of the class with the main method.

Package Sealing

You can seal one or more packages within the JAR file. This ensures that all the classes within the sealed package must be present within the JAR file. You do this my putting the following line in the manifest file for each package that needs to be sealed:

 Name: CompanyName/Package1/ Sealed: true 

Package Versioning

You can also define versioning information for a package within a JAR file. You need to define the versioning information underneath the package name within the manifest file. For example, the java.util package can be versioned like this:

 Name: java/util/ Specification-Title: "Java Utility Classes" Specification-Version: "1.2" Specification-Vendor: "Sun Microsystems, Inc." Implementation-Title: "java.util" Implementation-Version: "build57" Implementation-Vendor: "Sun Microsystems, Inc." 

Programs can use the methods available in the java.lang.Package to programmatically get the version information from a JAR file. In this way, an application can check to see which version of an application or package is loaded in the application.

Download Extension

Download extensions provide a way for manifest files to reference JAR files other than the one that the manifest file belongs to. This usually introduces itself it terms of the Java Extension mechanism that was introduced in the JDK 1.2 version. This enables custom APIs that are outside of the standard Java APIs to be referenced by the manifest file.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net