[jboss-user] [Beginners Corner] - Inserting custom classloader to delegation chain?

hentar do-not-reply at jboss.com
Wed Aug 15 11:24:02 EDT 2007


Hello.

I'm trying to define a custom classloader to create certain classes at runtime. 

My classloader itself is just deriving from ClassLoadder and overriding the findClass with something like


  | @Override
  | 	protected Class<?> findClass(String className) throws ClassNotFoundException {
  | 		ClassLoader parentLoader = this.getClass().getClassLoader();
  | 		if(className.equals("classToBeCreatedAtRuntime")){
  | 			Class c = createClass(className);
  | 			return c;
  | 		}else{
  | 			return Class.forName(className, true, parentLoader);
  | 		}
  | 	}
  |  

What I want from my classloader is to create and load class at runtime if needed or just delegate the responsibility to parent class loader.

The main problem I face is to "push" my custom loader into the delegation chain. I've tried to set it with Thread.currentThread().setContextClassLoader but I'm getting classcast exceptions, so this doesn't seems like a right way.

Am I missing something? How this can be achieved?

Thanks a lot.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074477#4074477

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074477



More information about the jboss-user mailing list