dev@glassfish.java.net

Re: Invoking method across modules

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Fri, 28 Mar 2008 16:25:44 -0700

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