tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Reflection > Where the Class loaded from

Where the Class loaded from 

The following code shows how to find the location from which the class has been loaded.

File Name  :  
com/bethecoder/tutorials/reflection/ClassLocation.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
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,

clslocation


 
  


  
bl  br