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);

}

}

}

[1312 byte] By [Generic_Programmera] at [2007-11-26 21:27:21]
# 1
In case anyone is wondering what self ID information in the manifest I am talking about--the custom ID information I am going to put there. I don't want to have to go back and modify the source code any time the name of the JAR file must change, which could one day become a requirement.
Generic_Programmera at 2007-7-10 3:07:57 > top of Java-index,Java Essentials,New To Java...