Created
September 22, 2017 07:34
-
-
Save thinkerzhangyan/89fc960a52b165aebe54cfb3d92ee2f7 to your computer and use it in GitHub Desktop.
ClassLoaderPropTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.net.*; | |
import java.io.*; | |
public class ClassLoaderPropTest | |
{ | |
public static void main(String[] args) | |
throws IOException | |
{ | |
// 获取系统类加载器 | |
ClassLoader systemLoader = ClassLoader.getSystemClassLoader(); | |
System.out.println("系统类加载器:" + systemLoader); | |
/* | |
获取系统类加载器的加载路径——通常由CLASSPATH环境变量指定 | |
如果操作系统没有指定CLASSPATH环境变量,默认以当前路径作为 | |
系统类加载器的加载路径 | |
*/ | |
Enumeration<URL> em1 = systemLoader.getResources(""); | |
while(em1.hasMoreElements()) | |
{ | |
System.out.println(em1.nextElement()); | |
} | |
// 获取系统类加载器的父类加载器:得到扩展类加载器 | |
ClassLoader extensionLader = systemLoader.getParent(); | |
System.out.println("扩展类加载器:" + extensionLader); | |
System.out.println("扩展类加载器的加载路径:System.getProperty("java.ext.dirs")); | |
System.out.println("扩展类加载器的parent:extensionLader.getParent());//打印的值是null,因为根类加载器不是用java代码实现的 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment