Skip to main content
Jump to: navigation, search

BundleProxyClassLoader recipe

Revision as of 15:18, 7 June 2006 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
import java.util.Enumeration;

import org.osgi.framework.Bundle;

public class BundleProxyClassLoader extends ClassLoader {

	private Bundle bundle;

	public BundleProxyClassLoader(Bundle bundle) {
	    this.bundle = bundle;

	//	 Note: Both ClassLoader.getResources(...) and bundle.getResources(...) consult 
	//	 the boot classloader. 	 As a result, BundleProxyClassLoader.getResources(...) 
	//	 might return duplicate results from the boot classloader. Prior to Java 5 
	//	 Classloader.getResources was marked final. If your target environment requires
	//	 at least Java 5 you can prevent the occurence of duplicate boot classloader 
	//	 resources by overriding ClassLoader.getResources(...) instead of 
	//	 ClassLoader.findResources(...).   
	public Enumeration findResources(String name) throws IOException {
	    return bundle.getResources(name);
	public URL getResource(String name) {
	    return bundle.getResource(name);

	public Class loadClass(String name) throws ClassNotFoundException {
	    return bundle.loadClass(name);

Back to the top