1 22 package org.objectweb.petals.component.common.util; 23 24 import java.io.File ; 25 import java.io.FileFilter ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 import java.net.URLClassLoader ; 29 import java.util.ArrayList ; 30 31 38 public class ClassLoaderUtil { 39 40 50 public static URLClassLoader createClassLoader(String rootPath, ClassLoader parent) { 51 52 File path = new File (rootPath); 53 54 FileFilter jarFileFilter = new FileFilter () { 55 public boolean accept(File f) { 56 return f.getName().toLowerCase().endsWith(".jar"); 57 } 58 }; 59 60 File [] files = path.listFiles(jarFileFilter); 61 62 ArrayList <URL > urls = new ArrayList <URL >(); 63 64 if (files != null && files.length > 0) { 65 for (File file : files) { 66 try { 67 urls.add(file.toURL()); 68 } catch (MalformedURLException e) { 69 } 71 } 72 } 73 return new URLClassLoader (urls.toArray(new URL [] {}), parent); 74 } 75 } 76 | Popular Tags |