Saturday 9 November 2013

How to know from where a Class was loaded in Java

import java.security.ProtectionDomain;
import java.io.*;
public class CodeLoc
{
    public void codeLoc()
    {
        ProtectionDomain protectionDomain = getClass().getProtectionDomain();
        File codeLoc = new File(protectionDomain.getCodeSource().getLocation().getFile());
        System.out.println("--------codeLoc="+codeLoc);
    }
    public static void main(String []args)
    {
        CodeLoc cl=new CodeLoc();
        cl.codeLoc();
    }
}

No comments:

Post a Comment