打印Class Path

import java.io.IOException;

import java.net.URL;

import java.net.URLClassLoader;

 

import sun.misc.Launcher;

import sun.misc.URLClassPath;

 

public class Main {

 

public static void main(String[] args) throws IOException {

//Boot Class Path

URLClassPath urlsClassPath = Launcher.getBootstrapClassPath();

System.out.println("---Boot Class Path ClassLoader:" + Launcher.getLauncher()); //$NON-NLS-1$

URL[] rootClassPathUrls = urlsClassPath.getURLs();

for (Object object : rootClassPathUrls) {

System.out.println(((URL) object).toString());

}

//System Class Path

URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

System.out.println("---System Class Path ClassLoader:" + classLoader); //$NON-NLS-1$

 

URL[] systemClassPathUrls = classLoader.getURLs();

for (Object object : systemClassPathUrls) {

System.out.println(((URL) object).toString());

}

//Extend Class Path

classLoader = (URLClassLoader) classLoader.getParent();

System.out.println("---Extended Class Path ClassLoader:" + classLoader); //$NON-NLS-1$

 

URL[] extenedClassPathUrls = classLoader.getURLs();

for (Object object : extenedClassPathUrls) {

System.out.println(((URL) object).toString());

}

}

}

 

你可能感兴趣的:(java,.net,sun)