Question: How would you go about establishing where a class ( or maybe resource ) has been loaded from?

I am trying to work out exactly where a class has been loaded from. Does anyone know if you can find out the following:

1. Which Jar file did the class come from ?
2. What classloader loaded the file?

Answer: 
The class `Class` has an instance method `getClassLoader()` that returns a reference to the class loader that loaded the class it represents. Note that this can return `null`. See [here](http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getClassLoader%28%29).

So, if you wanted to know which classloader loaded `String` (just as an example) you could do:

```
ClassLoader loader = String.class.getClassLoader();

```

or:

```
ClassLoader loader = "I'm a String".getClass().getClassLoader();

```
You can get an URL by calling MyClass.class.getResource("MyClass.class") for instance.