dev@glassfish.java.net

Re: Invoking method across modules

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Fri, 28 Mar 2008 15:39:21 -0700

I don't "think" it does. It builds with jsftemplating.jar (which
defines the HandlerContext class), but this maven dependency is marked
as "provided". The jsftemplating.jar file exists in the WEB-INF/lib
directory where it is found via the web-app classloader, but perhaps not
via the plugin-hk2-module classloader?

If it would be faster to talk over the phone, please let me know and
I'll call you. You can call me at x42083.

Thanks!!

Ken

Jerome Dochez wrote:
> well, you are not getting a class cast exception but a class not
> defined so I don't think it's because you use different class loader.
> does the plug-in module have visibility on the HandlerClass ?
>
> jerome
>
> Ken Paulsen wrote:
>>
>> Hi Jerome / Kohsuke (or anyone that can help),
>>
>>
>> The admin GUI provides a @Contract for anyone to implement via a
>> @Service. I get the implementations and can iterate over them, and
>> using their individual ClassLoaders, I can get resources from these
>> jar file (i.e. configuration files). This works fine.
>>
>> Now, I want to be able to use the ClassLoader supplied by one of
>> these modules to invoke Java code. I do this:
>>
>> Class moduleClass = moduleClassLoader.loadClass(name);
>>
>> This works. However, I then do:
>>
>> moduleClass.getMethod("something", new Class[]
>> {HandlerContext.class});
>>
>> This blows up:
>>
>> java.lang.NoClassDefFoundError:
>> com/sun/jsftemplating/layout/descriptors/handler/HandlerContext
>> at java.lang.Class.getDeclaredMethods0(Native Method)
>> at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
>> at java.lang.Class.getMethod0(Class.java:2670)
>> at java.lang.Class.getMethod(Class.java:1603)
>> at
>> com.sun.jsftemplating.layout.descriptors.handler.HandlerDefinition.getHandlerMethod(HandlerDefinition.java:157)
>>
>>
>> Now I know "HandlerContext.class" that I pass into the getMethod()
>> call is loaded from a different ClassLoader than "moduleClass" which
>> I believe is the problem... the question is: How do I resolve this?
>> Or: How should I be doing this differently? I suspect I'm also in
>> for more problems as other classes in the "something" method also
>> need to be resolved.
>>
>> Thanks,
>>
>> Ken
>