|
Where the Class loaded from
The following code shows how to find the location from which the class has been loaded.
|
package com.bethecoder.tutorials.reflection;
import java.security.CodeSource;
public class ClassLocation {
public static void main(String[] args) {
showSourcePath(ClassLocation.class);
}
public static void showSourcePath(Class cls) {
CodeSource source = cls.getProtectionDomain().getCodeSource();
System.out.println("Class loaded from : " + source.getLocation());
}
}
|
| |
It gives the following output,
|
|