You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Shash Chatterjee <sh...@hotmail.com> on 2002/11/07 04:34:26 UTC

Custom ClassLoader with Fortress

Hi,

I am trying to get Fortress to use a custom classloader (source attached).
The only difference from URLClassLoader is that I don't want to check the
parent classloader first to load the class.

This works fine with my test classes/packages.  However, when I use it with
Fortress, o.a.e.f.AbstractContainer#getComponentHandler gets a
NoSuchMethodException whenever it tries to get the constructor for
ThreadSafeComponentHandler.  I tried getting handlerKlass.constructors()[0]
explicitly, and in the debugger I see that it is the right constructor, with
the 6 correct parameter types.  But when the next line calls
newInstance(Object[] {....}), it gets a invalid parameter exception.

If I replace KeelURLClassLoader with URLClassLoader and change nothing else,
everything works fine.  If I use KeelURLClassLoader, but force it to get the
class from the parent classloader, then everything works fine.  The problem
happens whenever KeelURLClassLoder#findClass() is called!

I have been staring at this for two days and am at wit's end.....any help
would be much appreciated.

Thanks,
Shash

PS: If it makes a difference, here's how I am setting the loader.  I am
using the identical (system) classpath for both the parent and custom
class-loaders for the test.

ClassLoader loader = new KeelURLClassLoader(
                   new
URLClassLoaderPath(System.getProperty("java.class.path").getURLArray(),
                   ClassLoader.getSystemClassLoader());
contextBuilder.setContextClassLoader(loader);
containerManager = new DefaultContainerManager(
                    contextBuilder.getContext(), log);
containerManager.initialize();

RE: Custom ClassLoader with Fortress

Posted by Berin Loritsch <bl...@apache.org>.
> From: Shash Chatterjee [mailto:shash_list@hotmail.com] 
> 
> Hi,
> 
> I am trying to get Fortress to use a custom classloader 
> (source attached).
> The only difference from URLClassLoader is that I don't want 
> to check the
> parent classloader first to load the class.
> 
> This works fine with my test classes/packages.  However, when 
> I use it with
> Fortress, o.a.e.f.AbstractContainer#getComponentHandler gets a
> NoSuchMethodException whenever it tries to get the constructor for
> ThreadSafeComponentHandler.  I tried getting 
> handlerKlass.constructors()[0]
> explicitly, and in the debugger I see that it is the right 
> constructor, with
> the 6 correct parameter types.  But when the next line calls
> newInstance(Object[] {....}), it gets a invalid parameter exception.



The problem has to do with the fact that you altered the contract
for ClassLaoders.  By not allowing the delegation to the parent (or
even resolving first), the class in question is not treated as equal
to one in the parent classloader--even if they come from the same
JAR file.

The short solution is to not make that modification to the classloader
contract--which Fortress was counting on.  The longer solution is to
modify Fortress to use the ClassLoader that loaded the container classes
to load the handler classes.  The custom classloader would be used
for your class specifically.

However, that may not work because of the need to resolve things like
Configuration, Context, etc.  All of these need to come from the same
classloader.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>