1 16 17 18 package org.webdocwf.util.loader.generator; 19 20 import java.io.*; 21 import java.net.*; 22 import java.lang.reflect.*; 23 24 30 public class GeneratorClassLoader { 31 32 private static final Class [] parameters = new Class [] { 33 URL.class}; 34 35 40 public static void addFile(String s) throws IOException { 41 42 File f = new File(s); 43 44 addFile(f); 45 46 } 48 53 public static void addFile(File f) throws IOException { 54 55 addURL(f.toURL()); 56 57 } 59 64 public static void addURL(URL u) throws IOException { 65 66 URLClassLoader sysloader = (URLClassLoader) ClassLoader. 67 getSystemClassLoader(); 68 69 Class sysclass = URLClassLoader.class; 70 71 try { 72 73 Method method = sysclass.getDeclaredMethod("addURL", parameters); 74 75 method.setAccessible(true); 76 77 method.invoke(sysloader, new Object [] {u}); 78 79 } 80 catch (Throwable t) { 81 82 t.printStackTrace(); 83 84 throw new IOException("Error, could not add URL to system classloader"); 85 86 } 88 } 90 } | Popular Tags |