All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.libg.classloaders.URLClassLoaderWrapper Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
package aQute.libg.classloaders;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class URLClassLoaderWrapper {
	final URLClassLoader	loader;
	final Method			addURL;

	public URLClassLoaderWrapper(ClassLoader loader) throws Exception {
		this.loader = (URLClassLoader) loader;
		addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
		addURL.setAccessible(true);
	}

	public void addURL(URL url) throws Exception {
		try {
			addURL.invoke(loader, url);
		} catch (InvocationTargetException ite) {
			throw (Exception) ite.getTargetException();
		}
	}

	public Class< ? > loadClass(String name) throws Exception {
		return loader.loadClass(name);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy