Java ClassPath Get getClasspath()

Here you can find the source of getClasspath()

Description

Get the current classpath.

License

Open Source License

Return

the current classpath or the empty array if an error occurs.

Declaration

public static URL[] getClasspath() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class Main {
    private static final Class<?>[] noparams = new Class[0];

    /**//from  ww  w.ja va2  s  .  c o  m
     * Get the current classpath.
     * @return the current classpath or the empty array if an error occurs.
     */
    public static URL[] getClasspath() {
        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];
        }
    }
}

Related

  1. getClasspath()
  2. getClasspath()
  3. getClasspath()
  4. getClassPath()
  5. getClasspath()
  6. getClassPath()
  7. getClassPath(Class c)
  8. getClassPath(Class clazz)
  9. getClasspath(ClassLoader classLoader)