Java ClassPath toClasspathString(ClassLoader cl)

Here you can find the source of toClasspathString(ClassLoader cl)

Description

to Classpath String

License

LGPL

Declaration

public static String toClasspathString(ClassLoader cl) throws Exception 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;

import java.net.URL;
import java.net.URLClassLoader;

public class Main {
    public static String toClasspathString(ClassLoader cl) throws Exception {
        if (cl == null) {
            cl = Thread.currentThread().getContextClassLoader();
        }/*from  w  w  w.ja va2 s .c  o  m*/
        StringBuilder back = new StringBuilder();
        while (cl != null) {
            if (cl instanceof URLClassLoader) {
                URLClassLoader ucl = (URLClassLoader) cl;
                URL[] urls = ucl.getURLs();
                for (URL url : urls) {
                    if (back.length() != 0) {
                        back.append(File.pathSeparatorChar);
                    }
                    back.append(url.getFile());
                }
            }
            cl = cl.getParent();
        }
        return back.toString();
    }
}

Related

  1. printJVMClassPath()
  2. readFileFromClasspath(String fileName)
  3. readFromClassPath(String filePath)
  4. readStringFromClasspath(String path, Class c)
  5. toClassLoaderWithDefaultParent(Collection classPaths)
  6. toFiles(String classPath)
  7. tryToGetClassPath(ClassLoader cl)