/** @return returns a string list of all pathes */ public static Resource[] getClassPathes() { if (classPathes != null) return classPathes; ArrayList pathes = new ArrayList(); String pathSeperator = System.getProperty("path.separator"); if (pathSeperator == null) pathSeperator = ";"; // java.ext.dirs ResourceProvider frp = ResourcesImpl.getFileResourceProvider(); // pathes from system properties String strPathes = System.getProperty("java.class.path"); if (strPathes != null) { Array arr = ListUtil.listToArrayRemoveEmpty(strPathes, pathSeperator); int len = arr.size(); for (int i = 1; i <= len; i++) { Resource file = frp.getResource(Caster.toString(arr.get(i, ""), "").trim()); if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file)); } } // pathes from url class Loader (dynamic loaded classes) ClassLoader cl = new Info().getClass().getClassLoader(); if (cl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) cl, pathes); return classPathes = (Resource[]) pathes.toArray(new Resource[pathes.size()]); }
/** * get class pathes from all url ClassLoaders * * @param ucl URL Class Loader * @param pathes Hashmap with allpathes */ private static void getClassPathesFromClassLoader(URLClassLoader ucl, ArrayList pathes) { ClassLoader pcl = ucl.getParent(); // parent first if (pcl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) pcl, pathes); ResourceProvider frp = ResourcesImpl.getFileResourceProvider(); // get all pathes URL[] urls = ucl.getURLs(); for (int i = 0; i < urls.length; i++) { Resource file = frp.getResource(urls[i].getPath()); if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file)); } }