static URL[] findClasspathURLS(String classpathStr) throws MalformedURLException { /* If harvester.home is set, then the classpath urls should be taken as relative to that path. */ String homePath = System.getProperty(Strings.HARVESTER_DOT_HOME); System.out.println("harvester.home=" + homePath); log.log(Level.FINE, MessageNames.HOMEPATH_IS, homePath); File homePathFile = (homePath == null) ? new File(Strings.DOT) : new File(homePath); StringTokenizer tok = new StringTokenizer(classpathStr, Strings.WHITESPACE_SEPARATORS); List<URL> pathElements = new ArrayList<URL>(); while (tok.hasMoreTokens()) { File f = new File(homePathFile, tok.nextToken()); pathElements.add(f.toURI().toURL()); } URL[] urls = (URL[]) pathElements.toArray(new URL[0]); return urls; }
private static ClassLoader resolveClassLoader( Map<String, ClassLoader> classLoaders, List<String> seen, Map<String, Classpath> classpaths, String id) throws MalformedURLException { if (classLoaders.containsKey(id)) { return classLoaders.get(id); } if (seen.contains(id)) { throw new ConfigurationException(MessageNames.CIRCULAR_CLASSPATH, id); } // Add the id to the list of classloaders we have attempted to build. seen.add(id); Classpath classpath = classpaths.get(id); if (classpath == null) { throw new ConfigurationException(MessageNames.CLASSPATH_UNDEFINED, id); } String parentClasspathId = classpath.getParent(); ClassLoader parentClassLoader = null; if (parentClasspathId != null && !Strings.EMPTY.equals(parentClasspathId)) { parentClassLoader = resolveClassLoader(classLoaders, seen, classpaths, parentClasspathId); } else { /* Should be the 'extension' classloader. */ parentClassLoader = Bootstrap.class.getClassLoader().getParent(); } URL[] classpathUrls; classpathUrls = findClasspathURLS(classpath.getValue()); SettableCodebaseClassLoader classLoader = new SettableCodebaseClassLoader(classpathUrls, parentClassLoader); classLoaders.put(id, classLoader); log.log( Level.FINE, MessageNames.CONFIGURED_CLASSPATH, new Object[] {id, Utils.format(classpathUrls)}); seen.remove(id); return classLoader; }