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
http://www.rgagnon.com/javadetails/java-0665.html
List 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)