The Java Developers Almanac 1.4


Order this book from Amazon.

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

e383. Writing a JAR File Manifest to a File

The format of a manifest file is described in:
    http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html
This example retrieves the manifest from a JAR file and writes the manifest contents to a file.
    try {
        // Open the JAR file
        JarFile jarfile = new JarFile("filename.jar");
    
        // Get the manifest
        Manifest manifest = jarfile.getManifest();
    
        // Write the manifest to a file
        OutputStream fos = new FileOutputStream("manifest");
        jarfile.getManifest().write(fos);
        fos.close();
    } catch (IOException e) {
    }
Here's an example of a manifest file:
    Manifest-Version: 1.0
    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-rc (Sun Microsystems Inc.)
    Implementation-Vendor: Sun Microsystems, Inc.
    Specification-Vendor: Sun Microsystems, Inc.
    
    Name: javax/swing/JScrollPane.class
    Java-Bean: True
    
    Name: javax/swing/JCheckBoxMenuItem.class
    Java-Bean: True
    
    Name: javax/swing/JTabbedPane.class
    Java-Bean: True
    
    Name: javax/swing/JMenuItem.class
    Java-Bean: True
    
    Name: javax/swing/JTable.class
    Java-Bean: True

 Related Examples
e380. Listing the Entries of a JAR File Manifest
e381. Listing the Main Attributes in a JAR File Manifest
e382. Creating a Manifest for a JAR File
e384. Creating and Signing a JAR File Using jarsigner


© 2002 Addison-Wesley.