Skip to content

Instantly share code, notes, and snippets.

@cliff76
Created October 30, 2013 03:01
Show Gist options
  • Select an option

  • Save cliff76/7226579 to your computer and use it in GitHub Desktop.

Select an option

Save cliff76/7226579 to your computer and use it in GitHub Desktop.
Classpath Prober
import java.net.URISyntaxException;
public class ClassLoaders {
static void handle(Throwable e){
throw new RuntimeException("Exception " + e, e);
}
static void load(String toLoad) {
String resRef = toLoad.replaceAll("\\.","/") + ".class";
System.out.println("Loading " + toLoad + " using resource id " + resRef);
String url = null;
try {
url = ClassLoaders.class.getResource(resRef).toURI().toString();
} catch (URISyntaxException e) {
handle(e);
}
System.out.println("Loader from url " + url);
Class theClass=null;
try {
theClass = Class.forName(toLoad);
} catch (ClassNotFoundException e) {
handle(e);
}
System.out.println("Loaded by Classloader " + theClass.getClassLoader());
}
public static void main(String[] args) {
System.out.println("ClassLoaders.java args: " + args.length);
String toLoad = (args.length > 0) ? args[0] : "org.junit.Test";
load(toLoad);
System.exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment