? .ClassPather.java.swp ? ktrace.out ? net Index: ClassPathHacker.java =================================================================== RCS file: /cvsroot/shp2kml/KMLer/net/sourceforge/shp2kml/Attic/ClassPathHacker.java,v retrieving revision 1.3 diff -u -u -r1.3 ClassPathHacker.java --- ClassPathHacker.java 25 Aug 2005 13:40:06 -0000 1.3 +++ ClassPathHacker.java 29 Aug 2005 01:53:14 -0000 @@ -20,6 +20,7 @@ public static void addURL(URL u) throws IOException { URL urls[] = new URL[] { u }; + System.out.println("url: " + u.toString()); ClassLoader aCL = Thread.currentThread().getContextClassLoader(); URLClassLoader aUrlCL = new URLClassLoader(urls, aCL); Index: ClassPather.java =================================================================== RCS file: /cvsroot/shp2kml/KMLer/net/sourceforge/shp2kml/Attic/ClassPather.java,v retrieving revision 1.2 diff -u -u -r1.2 ClassPather.java --- ClassPather.java 24 Aug 2005 02:32:04 -0000 1.2 +++ ClassPather.java 29 Aug 2005 01:53:14 -0000 @@ -1,33 +1,62 @@ package net.sourceforge.shp2kml; import java.io.File; +import java.io.FileFilter; import java.io.FilenameFilter; import java.io.IOException; +import java.lang.reflect.Method; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; + +import java.util.LinkedList; + /* * Created on Aug 21, 2005 */ public class ClassPather { - public static void loadClasses(String dirStr) { + public static ClassLoader loadClasses(String dirStr) + throws MalformedURLException { + return loadClasses(new File(dirStr)); + } - File dir; - dir = new File(dirStr); + public static ClassLoader loadClasses(File dir) + throws MalformedURLException { + LinkedList urls = new LinkedList(); + loadClasses(dir, urls); + + System.out.println("thread: " + Thread.currentThread().toString()); + + URL[] urlsArray = (URL[]) urls.toArray(new URL[0]); + + for (int i = 0; i < urlsArray.length; i++) { + System.out.println("url: " + urlsArray[i].toString()); + } + +// ClassLoader aCL = Thread.currentThread().getContextClassLoader(); +// URLClassLoader aUrlCL = new URLClassLoader(urlsArray, aCL); +// URLClassLoader aUrlCL = new URLClassLoader(urlsArray); + URLClassLoader aUrlCL = URLClassLoader.newInstance(urlsArray); - FilenameFilter dirFilter = new FilenameFilter() { - public boolean accept(File dir, String name) { + return aUrlCL; +// Thread.currentThread().setContextClassLoader(aUrlCL); + } - File test = new File(dir.getAbsoluteFile() + "/" + name); - return test.isDirectory(); + public static void loadClasses(File dir, LinkedList urls) + throws MalformedURLException { + FileFilter dirFilter = new FileFilter() { + public boolean accept(File pathname) { + return pathname.isDirectory(); } }; - String[] dirlist = dir.list(dirFilter); - int i = 0; - while (i < dirlist.length) { - ClassPather.loadClasses(dir.getAbsolutePath() + "/" + dirlist[i]); - i++; + File[] dirlist = dir.listFiles(dirFilter); + for (int i = 0; i < dirlist.length; i++) { + ClassPather.loadClasses(dirlist[i], urls); } // It is also possible to filter the list of returned files. @@ -38,32 +67,50 @@ } }; - String[] children = dir.list(jarFilter); - int j = 0; - String path = System.getProperty("java.class.path"); - String currJar; - while (j < children.length) { - // URLClassLoader cl = - // (URLClassLoader)ClassLoader.getSystemClassLoader(); - currJar = dir.getAbsolutePath() + "/" + children[j]; - path += ":" + currJar; - try { - ClassPathHacker.addFile(new File(currJar)); - System.setProperty("java.class.path", path); - } catch (IOException e) { - e.printStackTrace(); - } - j++; - } + File[] children = dir.listFiles(jarFilter); + for (int i = 0; i < children.length; i++) { + urls.add(children[i].toURL()); + } } - public static void main(String[] args) { - if (args.length == 1) { - ClassPather.loadClasses(args[1]); - } else { - System.out.println("Usage: classpather directory/to/scan/for/jars"); - - } + public static void main(String[] args) throws Exception { + if (args.length < 1) { + System.err.println("Usage: classpather