dev@glassfish.java.net

Re: Invoking method across modules

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Fri, 28 Mar 2008 16:33:06 -0700

Jerome Dochez wrote:
>
> On Mar 28, 2008, at 3:39 PM, Ken Paulsen wrote:
>
>>
>> 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?
> ok so you definitely have 2 class loaders loading the same class and
> conflicting...
> why is jsftemplating.jar part of the WEB-INF/lib ?
That's where it belongs. It doesn't exist anywhere else. FYI, I changed
from getMethod() to getMethods() and iterated over the Methods... same
exception:

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)


So I think it is simply that the HK2 module cannot find the
jsftemplating.jar classes when it loaded "moduleClass".

I would like to make the web-app classloader (actually my own
ClassLoader that wraps the web-app classloader) available while
loading/executing the method from the plugin jar. This way it will find
that class when loading / executing the code. Is that possible?

We can talk Monday as I know you're trying to deal with SCF things.

Thanks,

Ken


>> 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.
> I don't have much time today and since GUI is not part of SCF, can we
> wait for monday ?
Ok, let meet Monday.
>
>>
>>
>> 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
>>>
>