How to find out where a class is being loaded from

Sometimes you are interested in knowing where your code is getting a certain class from. Knowing this helps you with resolving conflicts.

Let's say in our ClassA, we are calling a certain API from ClassB, and that API is not functioning as we expect. We are interested to see which jar file ClassB is loaded from. To do this add the following line to you code and inspect or print the value of the returned string.

String mysteriousPath = ClassA.class.getResource("ClassB.class").openConnection().getURL().toString();

No comments:

Post a Comment