import java.io.*; import java.util.*; import java.util.jar.*; public class JarManifest { /** * main() */ public static void main(String[] args) throws IOException { // Open the jar file, using the first command line argument as the file // name. JarFile jar = new JarFile(args[0]); // Process the jar file. Close it when the block is exited. try { // Get the manifest. Manifest manifest = jar.getManifest(); // Loop through the manifest attributes. Print the key name and value // for each one. for (Iterator entries = manifest.getMainAttributes().entrySet().iterator(); entries.hasNext(); ) { Map.Entry entry = (Map.Entry) entries.next(); System.out.println(entry.getKey() + ": " + entry.getValue()); } System.out.println(""); // Loop through the manifest entries. Print the name and attributes of // each one. for (Iterator entries = manifest.getEntries().entrySet().iterator(); entries.hasNext(); ) { Map.Entry entry = (Map.Entry) entries.next(); System.out.println("Name: " + entry.getKey()); for (Iterator attributes = ((Attributes) entry.getValue()).entrySet().iterator(); attributes.hasNext(); ) { Map.Entry attribute = (Map.Entry) attributes.next(); System.out.println(attribute.getKey() + ": " + attribute.getValue()); } System.out.println(""); } } finally { jar.close(); } } }