Saturday, 11 June 2011

Find from which jar a class was loaded

In order to find at runtime where from file system a class was loaded, following command would be useful:
System.out.println(<myjavaclassname>
.class.getProtectionDomain()
.getCodeSource().getLocation());

Output will be something like this:
file:/C:/TestWorkSpace/lib/MyLibrary.jar

It can be helpful while debugging some class loading problems.

No comments:

Post a Comment