AGYNAMIX®.


Passionate Software.
29. Juli 2009

Java Tip: How to find the location of a class being executed

Today I wanted to find the location of a class file to make sure the class is really called from a specific jar file (old project with historically grown piles of archaeologically valuable code). Turns out this is pretty easy. For instance within the class you log the result of the following statement:

URI uri = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()

This will give you the exact place from witch the class was loaded.

Tags: programming english