The Dark Side Of A Developer

Tuesday, January 18, 2005

Jar Jar, where are you?

Sometime we want to create a JAR (Java ARchive file), may be of interest to know what is the JAR file that contains an specific class defenition at runtime. To know what is this JAR file, we must do the next:

try {

String myClassName = "";
String myJarName="";

myClassName=My_Instance_Of_A_Class.getClass().getName();
myClassName=.replace('.', /');

Class myClass=My_Instance_Of_A_Class.getClass();
myJarName=myClass.getResource("/"+myClassName+".class").toString();

int index=myJarName.lastIndexOf(":")-1;
int indexExclam=myJarName.indexOf("!");

myJarName=myJarName.substring(index,indexExclam);

} catch (Exception ex) {
/*There has been an error*/
}



... yes, my Master!


0 Comments:

Post a Comment

<< Home