URL url = Thread.currentThread().getContextClassLoader().getResource("com/example/ClassToFind.class");
if(url != null){
System.out.println(" location of resource in context "+url.getPath());
} else {
url = super.getClass().getClassLoader().getResource(name);
if(url != null){
System.out.println(" location of resource class loder "+ super.getClass().getClassLoader() + " is "+ url.getPath());
}
}
If the ClassToFind.class is in example.jar then the above will print
location-of-example.jar!com/example/ClassToFind.class
If you want to find all the jars containg the resource then you can use this instead.
java.util.Enumeration
.getResources("");
while(urls.hasMoreElements()){
System.out.println(urls.nextElement().getPath());
}
There are few other ways to get around this. If you have put Java in verbose mode or If you are running in JBOSS you can enable the class loader logs. see JBOSS docs for more information.

No comments:
Post a Comment