JavaXT

How to Parse Entries in a Manifest

Here's a simple script you can use to display all the properties stored in a Manifest.

    java.io.File file = new java.io.File("/Drivers/h2/h2-1.3.162.jar");
    java.util.jar.JarFile jar = new java.util.jar.JarFile(file);
    java.util.jar.Manifest manifest = jar.getManifest();

    System.out.println("\r\nMain Attributes:\r\n--------------------------");
    printAttributes(manifest.getMainAttributes());


    System.out.println("\r\nOther Attributes:\r\n--------------------------");
    java.util.Map<String, java.util.jar.Attributes> entries = manifest.getEntries();
    java.util.Iterator<String> it = entries.keySet().iterator();
    while (it.hasNext()){
        String key = it.next();
        printAttributes(entries.get(key));
        System.out.println();
    }

    jar.close();



    private static void printAttributes(java.util.jar.Attributes attributes){
        java.util.Iterator it = attributes.keySet().iterator();
        while (it.hasNext()){
            java.util.jar.Attributes.Name key = (java.util.jar.Attributes.Name) it.next();
            Object value = attributes.get(key);
            System.out.println(key + ":  " + value);
        }
    }

Note that these JAR utilities/functions and more are available in the javaxt.io.Jar class.

Related Articles