/** adds an entry to the class path */ public void addClassPath(String cp) { UnixFile f = new UnixFile(cp); // use the URLClassLoader if (useSystem) { try { addURL(f.toURL()); if (verbose) System.out.println("RJavaClassLoader: added '" + cp + "' to the URL class path loader"); // return; // we need to add it anyway so it appears in .jclassPath() } catch (Exception ufe) { } } UnixFile g = null; if (f.isFile() && (f.getName().endsWith(".jar") || f.getName().endsWith(".JAR"))) { g = new UnixJarFile(cp); if (verbose) System.out.println( "RJavaClassLoader: adding Java archive file '" + cp + "' to the internal class path"); } else if (f.isDirectory()) { g = new UnixDirectory(cp); if (verbose) System.out.println( "RJavaClassLoader: adding class directory '" + cp + "' to the internal class path"); } else if (verbose) System.err.println( f.exists() ? ("WARNING: the path '" + cp + "' is neither a directory nor a .jar file, it will NOT be added to the internal class path!") : ("WARNING: the path '" + cp + "' does NOT exist, it will NOT be added to the internal class path!")); if (g != null && !classPath.contains(g)) { // this is the real meat - add it to our internal list classPath.add(g); // this is just cosmetics - it doesn't really have any meaning System.setProperty( "java.class.path", System.getProperty("java.class.path") + File.pathSeparator + g.getPath()); } }
// {{{ findResource public URL findResource(String name) { if (verbose) System.out.println("RJavaClassLoader: findResource('" + name + "')"); // {{{ use the standard way if (useSystem) { try { URL u = super.findResource(name); if (u != null) { if (verbose) System.out.println("RJavaClassLoader: found resource in " + u + " using URL loader."); return u; } } catch (Exception fre) { } } // }}} // {{{ iterate through the classpath if (verbose) System.out.println(" - resource not found with URL loader, trying alternative"); Enumeration /*<UnixFile>*/ e = classPath.elements(); while (e.hasMoreElements()) { UnixFile cp = (UnixFile) e.nextElement(); try { /* is a file - assume it is a jar file */ if (cp instanceof UnixJarFile) { URL u = ((UnixJarFile) cp).getResource(name); if (u != null) { if (verbose) System.out.println(" - found in a JAR file, URL " + u); return u; } } else if (cp instanceof UnixDirectory) { UnixFile res_f = new UnixFile(cp.getPath() + "/" + name); if (res_f.isFile()) { if (verbose) System.out.println(" - find as a file: " + res_f); return res_f.toURL(); } } } catch (Exception iox) { } } // }}} return null; }