/** * Add a URL to the loader classpath only; does not update the system classpath. * * @param path to be added. * @throws MalformedURLException when <code>path</code> points to an invalid url */ public static void addURL(String path) throws MalformedURLException { File furl = new File(path); loader.addURL(furl.toURI().toURL()); // See Java bug 4496398 File[] jars = listJars(furl); for (File jar : jars) { loader.addURL(jar.toURI().toURL()); // See Java bug 4496398 } }
/** * Add a directory or jar to the loader and system classpaths. * * @param path * to add to the loader and system classpath * @throws MalformedURLException * if <code>path</code> can not be transformed to a valid * {@link URL} */ public static void addPath(String path) throws MalformedURLException { File file = new File(path); // Ensure that directory URLs end in "/" if (file.isDirectory() && !path.endsWith("/")) {// $NON-NLS-1$ file = new File(path + "/");// $NON-NLS-1$ } loader.addURL(file.toURI().toURL()); // See Java bug 4496398 StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH)); sb.append(CLASSPATH_SEPARATOR); sb.append(path); File[] jars = listJars(file); for (File jar : jars) { loader.addURL(jar.toURI().toURL()); // See Java bug 4496398 sb.append(CLASSPATH_SEPARATOR); sb.append(jar.getPath()); } // ClassFinder needs this System.setProperty(JAVA_CLASS_PATH,sb.toString()); }