Java Utililty Methods ClassPath Get

List of utility methods to do ClassPath Get

Description

The list of methods to do ClassPath Get are organized into topic(s).

Method

ClassgetClassFromLibs(String className, List libs, boolean useSystemClassPath)
get Class From Libs
ClassLoader clr = createClassLoader(libs, useSystemClassPath);
return (Class<T>) clr.loadClass(className);
SetgetClassLoaderClasspath(ClassLoader loader)
get Class Loader Classpath
LinkedHashSet<URL> jars = new LinkedHashSet<URL>();
getClassLoaderClasspath(loader, jars);
return jars;
StringgetClassPath()
get Class Path
String classpath = "";
URL resource = Thread.currentThread().getContextClassLoader().getResource("");
if (resource != null) {
    classpath = resource.getPath();
return classpath;
ListgetClasspath()
get Classpath
return Arrays.asList(getClassLoader().getURLs());
StringgetClasspath()
Returns the classpath, prefaced by the string 'Classpath:\n'.
StringBuilder sb = new StringBuilder("Classpath:\n");
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
for (URL url : urls) {
    sb.append(url.getFile()).append("\n");
return sb.toString();
StringgetClassPath()
get Class Path
StringBuffer buf = new StringBuffer();
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
for (URL url : urls) {
    if (buf.length() > 0)
        buf.append(";");
    buf.append(url.getFile());
return buf.toString();
ListgetClasspath()
get Classpath
ArrayList<URL> classpath = new ArrayList<URL>();
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
for (URL url : urls) {
    classpath.add(url);
return classpath;
URL[]getClasspath()
Get the current classpath.
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<?> sysclass = URLClassLoader.class;
try {
    Method method = sysclass.getDeclaredMethod("getURLs", noparams);
    method.setAccessible(true);
    return (URL[]) method.invoke(sysloader, new Object[0]);
} catch (Throwable t) {
    return new URL[0];
...
ListgetClasspath()
get Classpath
Function<URL, URI> func = new Function<URL, URI>() {
    @Override
    public URI apply(URL f) {
        try {
            return f.toURI();
        } catch (URISyntaxException ex) {
            throw new RuntimeException(ex);
};
return Lists.transform(Arrays.asList(getClassLoader().getURLs()), func);
URLgetClassPath(Class c)
get Class Path
String classFile = c.getName().replace('.', '/') + ".class";
URL url = c.getClassLoader().getResource(classFile);
if (url == null)
    return null;
if (url.getProtocol().equals("jar")) {
    String urlFile = url.getFile();
    int i = urlFile.indexOf("!");
    if (i > 0) {
...