<pre name="code" class="java">public class testClassLoader {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
MyURLClassLoader classLoader = new MyURLClassLoader();
Class classLoaded = classLoader.loadClass("com.microbots.controller.user");
System.out.println(classLoaded.getName());
classLoaded = null;
classLoader = null;
System.out.println("开始GC");
System.gc();
System.out.println("GC完成");
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.io.File;import java.net.URL;import java.net.URLClassLoader;public class MyURLClassLoader extends URLClassLoader { public MyURLClassLoader() { super(getMyURLs()); } private static URL[] getMyURLs() { try { return new URL[]{new File ("D:/yang/class").toURL()}; } catch (Exception e) { e.printStackTrace(); return null; } } }