<p>Does anyone know how to programmaticly find out where the java classloader actually loads the class from?  </p>

<p>I often work on large projects where the classpath gets very long and manual searching is not really an option.  I recently had a <a href="https://stackoverflow.com/questions/226280/eclipse-class-version-bug" title="problem">problem</a> where the classloader was loading an incorrect version of a class because it was on the classpath in two different places.</p>

<p>So how can I get the classloader to tell me where on disk the actual class file is coming from?</p>

<p><strong><em>Edit:</em></strong> What about if the classloader actually fails to load the class due to a version mismatch (or something else),  is there anyway we could find out what file its trying to read before it reads it?</p>

Assuming that you're working with a class named
```
MyClass
```
, the following should work:
```
```
MyClass.class.getClassLoader();
```
```
Whether or not you can get the on-disk location of the .class file is dependent on the classloader itself.  For example, if you're using something like BCEL, a certain class may not even have an on-disk representation.