Monday, February 15, 2010

Locate any java class file in your filesystem in runtime

package sunels;

import java.security.*;
import java.net.URL;

public class ClasspathUtil {
public static void main (String[] args) {
ClasspathUtil classpathutil = new ClasspathUtil ();
ProtectionDomain pDomain = classpathutil.getClass().getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation();
System.out.println (" -- Class< " + classpathutil.getClass().getCanonicalName() + "> Found in : {" + classpathutil.getClass().getCanonicalName() + " :" + loc+"}");
System.exit (0);
}
}
note: This example is finding itself

No comments:

Post a Comment