Writing a class to provide Self ID capability in a JAR file.
Hello,
I need to write a class which reads and prints out the contents of the manifest file of the JAR file of which it is a part. I've got the code for reading the manifest file, which I've included below.
My question is this: how can I get this class to find out the name of the JAR file it's in so I don't have to hard code "myJar.jar" as I have below?
Thanks.
import java.util.*;
import java.util.jar.*;
import java.io.*;
public class SelfID {
public static void main(String[] args) throws IOException {
System.out.println("The manifest for this jar file:");
//Create JarFile reference
JarFile jarFile = new JarFile("myJar.jar"); //I don't want Jar File name hard coded
//Create Manifest reference
Manifest manifest = jarFile.getManifest();
System.out.println(manifest.toString());
//Create Map of manifest key/value entries
Map entryMap = null;
entryMap = manifest.getMainAttributes();
//Display contents of manifest file
Iterator it = entryMap.keySet().iterator();
while( it.hasNext() ) {
Attributes.Name key = (Attributes.Name)it.next();
String value = (String)entryMap.get(key);
System.out.println(key.toString() + " = " + value);
}
}
}

