java应用环境中不同的class分别由不同的ClassLoader负责加载。
一个jvm中默认的classloader有Bootstrap ClassLoader、Extension ClassLoader、App ClassLoader,分别各司其职:
Bootstrap ClassLoader
负责加载java基础类,主要是 %JRE_HOME/lib/ 目录下的rt.jar、resources.jar、charsets.jar和class等
Extension ClassLoader
负责加载java扩展类,主要是 %JRE_HOME/lib/ext 目录下的jar和class
App ClassLoader
负责加载当前java应用的classpath中的所有类。
其中Bootstrap ClassLoader是JVM级别的,由C++撰写;
Extension ClassLoader、App ClassLoader都是java类,都继承自URLClassLoader超类。
Bootstrap ClassLoader由JVM启动,然后初始化sun.misc.Launcher ,sun.misc.Launcher初始化Extension ClassLoader、App ClassLoader。
在jdk1.6.0_10\jre\lib下面有Launcher。看jdk包自带的源码 src中有Launcher的文件夹,里面是些c文件!
下面是维基的原语
[quote]
The bootstrap class loader loads the core Java libraries[5] (<JAVA_HOME>/lib directory). This class loader, which is part of the core JVM, is written in native code.
(上面的注释[5]: These libraries are stored in Jar files called rt.jar, core.jar, server.jar, etc.)
The extensions(扩展) class loader loads the code in the extensions directories (<JAVA_HOME>/lib/ext or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.
(如果要引用ext下面的类 会提示你这些类是限制(restriction)访问的....
java.ext.dirs=C:\Program Files\Java\jdk1.6.0_10\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext)
The system class loader loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.
[/quote]
sun.misc.Launcher$AppClassLoader class.和sun.misc.Launcher$ExtClassLoader class.都在jre/lib/rt.jar下的包内
这些都是 Lantcher的内部类
看Launcher的一段代码 反编译过来的
一个jvm中默认的classloader有Bootstrap ClassLoader、Extension ClassLoader、App ClassLoader,分别各司其职:
Bootstrap ClassLoader
负责加载java基础类,主要是 %JRE_HOME/lib/ 目录下的rt.jar、resources.jar、charsets.jar和class等
Extension ClassLoader
负责加载java扩展类,主要是 %JRE_HOME/lib/ext 目录下的jar和class
App ClassLoader
负责加载当前java应用的classpath中的所有类。
其中Bootstrap ClassLoader是JVM级别的,由C++撰写;
Extension ClassLoader、App ClassLoader都是java类,都继承自URLClassLoader超类。
Bootstrap ClassLoader由JVM启动,然后初始化sun.misc.Launcher ,sun.misc.Launcher初始化Extension ClassLoader、App ClassLoader。
在jdk1.6.0_10\jre\lib下面有Launcher。看jdk包自带的源码 src中有Launcher的文件夹,里面是些c文件!
下面是维基的原语
[quote]
The bootstrap class loader loads the core Java libraries[5] (<JAVA_HOME>/lib directory). This class loader, which is part of the core JVM, is written in native code.
(上面的注释[5]: These libraries are stored in Jar files called rt.jar, core.jar, server.jar, etc.)
The extensions(扩展) class loader loads the code in the extensions directories (<JAVA_HOME>/lib/ext or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.
(如果要引用ext下面的类 会提示你这些类是限制(restriction)访问的....
java.ext.dirs=C:\Program Files\Java\jdk1.6.0_10\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext)
The system class loader loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.
[/quote]
sun.misc.Launcher$AppClassLoader class.和sun.misc.Launcher$ExtClassLoader class.都在jre/lib/rt.jar下的包内
这些都是 Lantcher的内部类
看Launcher的一段代码 反编译过来的
ExtClassLoader extclassloader;
try
{
extclassloader = ExtClassLoader.getExtClassLoader();
}
catch(IOException ioexception)
{
throw new InternalError("Could not create extension class loader");
}
try
{
loader = AppClassLoader.getAppClassLoader(extclassloader);
}
catch(IOException ioexception1)
{
throw new InternalError("Could not create application class loader");
}
Thread.currentThread().setContextClassLoader(loader);
String s = System.getProperty("java.security.manager");
if(s != null)
{
SecurityManager securitymanager = null;
if("".equals(s) || "default".equals(s))
securitymanager = new SecurityManager();
else
try
{
securitymanager = (SecurityManager)loader.loadClass(s).newInstance();
}
catch(IllegalAccessException illegalaccessexception) { }
catch(InstantiationException instantiationexception) { }
catch(ClassNotFoundException classnotfoundexception) { }
catch(ClassCastException classcastexception) { }
if(securitymanager != null)
System.setSecurityManager(securitymanager);
else
throw new InternalError((new StringBuilder()).append("Could not create SecurityManager: ").append(s).toString());
}