Where does this class came from?

Today I have been debugging some nasty problem on Weblogic. The application worked on one version but did not work on an older one. Apparently some classes were not compatible. But it's quite difficult to debug such problem. You need to find out from which JAR given class was taken from. It's not trivial in enterprise environment. The class can be part of J2SE, application server and your EAR at the same time. Especially if the class has something to do with XML or web services. End if you have such class, you need some trick to determine which version was actually used.

The trick is simple yet not widely known. In fact I have encountered it in a Scala related article. You just call this code from JSP or some other suitable place.

YourClass.class.getProtectionDomain().getCodeSource().getLocation()

And that's all, this command will return path to your mystery class JAR.

Tags: ,

One Response to “Where does this class came from?”

  1. jinxx Says:

    Nice post 🙂