Classloader issues - How to determine which library versions (jar-files) are loaded

Johan Pelgrim picture Johan Pelgrim · Sep 26, 2008 · Viewed 21.3k times · Source

I've just solved another *I-though-I-was-using-this-version-of-a-library-but-apparently-my-app-server-has-already-loaded-an-older-version-of-this-library-*issue (sigh).

Does anybody know a good way to verify (or monitor) whether your application has access to all the appropriate jar-files, or loaded class-versions?

Thanks in advance!

[P.S. A very good reason to start using the OSGi module architecture in my view!]

Update: This article helped as well! It gave me insight which classes JBoss' classloader loaded by writing it to a log file.

Answer

Tom picture Tom · Sep 26, 2008

If you happen to be using JBoss, there is an MBean (the class loader repository iirc) where you can ask for all classloaders that have loaded a certain class.

If all else fails, there's always 'java -verbose:class' which will print the location of the jar for every class file that is being loaded.