Mega Code Archive

 
Categories / Java / Reflection
 

Get the path from where a class is loaded

public class Main {   public static void main(String[] args) {     Main csl = new Main();     csl.getCodeSourceLocation();   }   private void getCodeSourceLocation() {     System.out.println("Code source location: "         + getClass().getProtectionDomain().getCodeSource().getLocation());   } }