概述
通过自定义类、系统类 获取 类加载器
实例
/**
* 获取类加载器
*/
public class Demo02 {
public static void main(String[] args) throws ClassNotFoundException {
// 获取系统类加载器
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
System.out.println(systemClassLoader);
// 获取系统类加载器的父类加载器
ClassLoader parent = systemClassLoader.getParent();
System.out.println(parent);
ClassLoader parent1 = parent.getParent();
System.out.println(parent1);
// 测试当前类是哪个加载器加载的
ClassLoader classLoader = Class.forName("com.gbhh.classloader.Demo02").getClassLoader();
System.out.println(classLoader);
// 测试jdk内置的类是谁
ClassLoader classLoader1 = Class.forName("java.lang.Object").getClassLoader();
System.out.println(classLoader1);
// 获取系统加载类可以加载的路径
System.out.println(System.getProperty("java.class.path"));
/*
D:应用开发环境Javajdk1.8.0_241jrelibcharsets.jar;
D:应用开发环境Javajdk1.8.0_241jrelibdeploy.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextaccess-bridge-64.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextcldrdata.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextdnsns.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextjaccess.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextjfxrt.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextlocaledata.jar;
D:应用开发环境Javajdk1.8.0_241jrelibext
ashorn.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextsunec.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextsunjce_provider.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextsunmscapi.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextsunpkcs11.jar;
D:应用开发环境Javajdk1.8.0_241jrelibextzipfs.jar;
D:应用开发环境Javajdk1.8.0_241jrelibjavaws.jar;
D:应用开发环境Javajdk1.8.0_241jrelibjce.jar;
D:应用开发环境Javajdk1.8.0_241jrelibjfr.jar;
D:应用开发环境Javajdk1.8.0_241jrelibjfxswt.jar;
D:应用开发环境Javajdk1.8.0_241jrelibjsse.jar;
D:应用开发环境Javajdk1.8.0_241jrelibmanagement-agent.jar;
D:应用开发环境Javajdk1.8.0_241jrelibplugin.jar;
D:应用开发环境Javajdk1.8.0_241jrelib
esources.jar;
D:应用开发环境Javajdk1.8.0_241jrelib
t.jar;
C:UserszglovDesktop注解和反射outproduction
eflection;
C:Program FilesJetBrainsIntelliJ IDEA 2020.1.3libidea_rt.jar
*/
}
}