Which jar

Monday, 23 April 2007, 23:22 | Category : Java, Technology
Tags :

How to know from which jar file a class has been loaded?

public static String whichJAR(Class clazz){
String name = clazz.getName();
name = name.substring(name.lastIndexOf(‘.’) + 1);
String jar = clazz.getResource(name + “.class”).toString(); //NOI18N
return jar.substring(0, jar.indexOf(‘!’));
}
  • gorlok

    Nice and simple.
    How I don’t think about it before?