The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util.jar  [5 examples]

e381. Listing the Main Attributes in a JAR File Manifest

The main attributes of a JAR file are values that are associated with the JAR file itself, not with any particular entry.
    try {
        // Open the JAR file
        JarFile jarfile = new JarFile("filename.jar");
    
        // Get the manifest
        Manifest manifest = jarfile.getManifest();
    
        // Get the main attributes in the manifest
        Attributes attrs = (Attributes)manifest.getMainAttributes();
    
        // Enumerate each attribute
        for (Iterator it=attrs.keySet().iterator(); it.hasNext(); ) {
            // Get attribute name
            Attributes.Name attrName = (Attributes.Name)it.next();
    
            // Get attribute value
            String attrValue = attrs.getValue(attrName);
        }
    } catch (IOException e) {
    }
Here's an example of main attributes for a JAR file:
    Attribute Name: Attribute Value
    
    Specification-Title: Java Platform API Specification
    Specification-Version: 1.4
    Implementation-Title: Java Runtime Environment
    Implementation-Version: 1.4.0-rc
    Created-By: 1.4.0 (Sun Microsystems Inc.)
    Manifest-Version: 1.0
    Implementation-Vendor: Sun Microsystems, Inc.
    Specification-Vendor: Sun Microsystems, Inc.

 Related Examples
e380. Listing the Entries of a JAR File Manifest
e382. Creating a Manifest for a JAR File
e383. Writing a JAR File Manifest to a File
e384. Creating and Signing a JAR File Using jarsigner


© 2002 Addison-Wesley.