1 21 22 23 package org.webdocwf.util.loader; 24 25 import java.io.*; 26 import java.net.*; 27 import java.lang.reflect.*; 28 29 35 public class OctopusClassLoader { 36 37 private static final Class [] parameters = new Class [] {URL.class}; 38 39 44 public static void addFile(String s) throws IOException { 45 46 File f = new File(s); 47 48 addFile(f); 49 50 } 52 57 public static void addFile(File f) throws IOException { 58 59 addURL(f.toURL()); 60 61 } 63 64 69 public static void addURL(URL u) throws IOException { 70 71 URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader(); 72 73 Class sysclass = URLClassLoader.class; 74 75 try { 76 77 Method method = sysclass.getDeclaredMethod("addURL", parameters); 78 79 method.setAccessible(true); 80 81 method.invoke(sysloader, new Object [] {u}); 82 83 } 84 catch (Throwable t) { 85 86 t.printStackTrace(); 87 88 throw new IOException("Error, could not add URL to system classloader"); 89 90 } 92 } 94 } | Popular Tags |