blob: 10ddca59f1af9f9ebfbd8d172fe34cfb98fadd68 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.libg.classloaders;
2
3import java.lang.reflect.*;
4import java.net.*;
5
6public class URLClassLoaderWrapper {
7 final URLClassLoader loader;
8 final Method addURL;
9
10 public URLClassLoaderWrapper(ClassLoader loader) throws Exception {
11 this.loader = (URLClassLoader) loader;
12 addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
13 addURL.setAccessible(true);
14 }
15
16 public void addURL(URL url) throws Exception {
17 try {
18 addURL.invoke(loader, url);
19 } catch( InvocationTargetException ite) {
20 throw (Exception) ite.getTargetException();
21 }
22 }
23
24 public Class<?> loadClass(String name) throws Exception {
25 return loader.loadClass(name);
26 }
27}