Java/Development Class/URLClassLoader
Load a Class that is not on the classpath
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
public class Main {
public static void main(String[] argv) throws Exception {
File file = new File("c:\\class\\");
URL url = file.toURI().toURL();
URL[] urls = new URL[] { url };
ClassLoader loader = new URLClassLoader(urls);
Class cls = loader.loadClass("user.informatin.Class");
}
}
Print classpath
import java.net.URL;
import java.net.URLClassLoader;
public class Main {
public static void main(String[] args) {
ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();
for (int i = 0; i < urls.length; i++) {
System.out.println(urls[i].getFile());
}
}
}