public class One {
public static void main(String[] args) throws Exception {
ClassLoader loader=One.class.getClassLoader();
System.out.println(loader);
//获得当前线程的上下文加载器,未改变前和第一种是一样的
ClassLoader loader2=Thread.currentThread().getContextClassLoader();
System.out.println(loader2);
//修改当前线程的上下文修改器
Thread.currentThread().setContextClassLoader(new Loader("d:/myjava"));
System.out.println(Thread.currentThread().getContextClassLoader());
Class<Dema> c=(Class<Dema>) Thread.currentThread().getContextClassLoader().loadClass("cn.sxt.in.Dema");
System.out.println(c);
System.out.println(c.getClassLoader()); //因为定义了父类委派机制,所以还是app加载
}
}
原文地址:https://blog.51cto.com/14437184/2439604
时间: 2024-11-11 00:43:26