Get classpath for current running thread



http://www.coderanch.com/t/603661/java/java/classpath-current-running-thread

void displayClassPath() {
 
     ClassLoader classloader = Thread.currentThread().getContextClassLoader();
 
     do {
         URL[] urls = ((URLClassLoader)classloader).getURLs();
 
         for(URL url: urls){
             System.out.println(url.getFile());
         }
         classloader = (URLClassLoader)classloader.getParent();
 
     } while(classloader != null);
 }



get system class path
  public static void main (String args[]) {

        ClassLoader cl = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader)cl).getURLs();

        for(URL url: urls){
        System.out.println(url.getFile());
        }
        
   }

List all files in the classpath or in a Jar
List<File> list = FileUtils.getFiles(System.getProperty("java.class.path"));
    for (File file: list) {
      System.out.println(file.getPath());
    }
   
    list = FileUtils.getFiles(System.getProperty("sun.boot.class.path"));
    for (File file: list) {
      System.out.println(file.getPath());
    }
    list = FileUtils.getFiles(System.getProperty("java.ext.dirs"));
    for (File file: list) {
      System.out.println(file.getPath());
    }

阅读更多
个人分类: JAVA
上一篇Package javax.ws.rs
下一篇在Linux执行命令报错”Arg list too long”的原因分析
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭