List of utility methods to do ClassPath
String | calculateClassPath(ClassLoader cl) calculate local file based class path for class loader if possible (servlet classes must be located there) StringBuffer classPath = new StringBuffer(); boolean jspFound = false, servletFound = false; while (cl != null) { if (cl instanceof URLClassLoader) { boolean addClasses = false; if (jspFound == false) { jspFound = ((URLClassLoader) cl).findResource("javax/servlet/jsp/JspPage.class") != null; addClasses |= jspFound; ... |
URLClassLoader | createClassLoader(List create Class Loader List<URL> urls = new ArrayList<>(); for (String path : paths) { URL url = pathToUrl(path); urls.add(url); for (Object object : classpathElements) { if (object != null) { String path = object.toString(); ... |
ClassLoader | createClassLoader(List create Class Loader List<URL> urls = new ArrayList<>(libs.size()); libs.forEach(lib -> { try { urls.add((new File(lib)).toURI().toURL()); } catch (MalformedURLException e) { throw new RuntimeException("The file wasn't readable: " + lib, e); }); ... |
URL[] | createClassPath(File file) create Class Path URL[] urls = null; if ((file.exists()) && (file.isDirectory())) { String[] jars = file.list(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.endsWith(".jar")) { return true; return false; ... |
void | dumpClasspath(ClassLoader loader) dump Classpath System.out.println("Classloader " + loader + ":"); if (loader instanceof URLClassLoader) { URLClassLoader ucl = (URLClassLoader) loader; System.out.println("\t" + Arrays.toString(ucl.getURLs())); } else System.out.println("\t(cannot display components as not a URLClassLoader)"); if (loader.getParent() != null) dumpClasspath(loader.getParent()); ... |
boolean | existsInClasspath(Class clazz, String fileName) exists In Classpath URL dirURL = clazz.getResource("/" + fileName); return dirURL != null; |
boolean | existsInClasspath(final String fileName) exists In Classpath return getResourceFromClasspath(fileName) != null;
|
void | fillClassPath(ClassLoader cl, StringBuffer classpath) Walk the classloader hierarchy and add to the classpath while (cl != null) { if (cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); for (int i = 0; (urls != null) && i < urls.length; i++) { String path = urls[i].getPath(); if (path.length() >= 3 && path.charAt(0) == '/' && path.charAt(2) == ':') path = path.substring(1); classpath.append(URLDecoder.decode(path)); ... |
List | findClassPaths() find Class Paths List<URL> list = new ArrayList<URL>(); String classpath = System.getProperty("java.class.path"); StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); File fp = new File(path); if (!fp.exists()) throw new RuntimeException("File in java.class.path does not exist: " + fp); ... |
URL[] | findClassPaths() Uses the java.class.path system property to obtain a list of URLs that represent the CLASSPATH List<URL> list = new ArrayList<URL>(); String classpath = System.getProperty("java.class.path"); StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); File fp = new File(path); if (!fp.exists()) throw new RuntimeException("File in java.class.path does not exist: " + fp); ... |