tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Speed <psp...@progeeks.com>
Subject Re: Tomcat + jBoss: ClassLoader Woes
Date Fri, 01 Sep 2000 21:53:32 GMT
Hello,

	Welcome to the wonderful world of EJB. :)

	We experience the same problems with Weblogic.  Unfortunately,
it seems like the classloaders that are used by JNDI/RMI in our 
specific cases are not respecting the current classloader as a parent.

	Since it's a problem with those specific classloaders using
the system classloader instead of the current classloader, I'm not
sure there is any way around it.

	Hopefully I will be proven wrong.
	-Paul

Aaron Mulder wrote:
> 
>         Sorry for the cross-post, but I'm looking for ideas wherever I can
> find them.  I'm trying to hook up Tomcat and jBoss so I can call EJBs from
> JSPs.  I believe the problems I'm having are caused by the proliferation
> of ClassLoaders.
>         Initially, I ran both Tomcat and jBoss in one VM, but I ran into
> ClassCastExceptions when I look up EJB objects in JNDI.  That is, the
> code:
>         Context ctx = new InitialContext();
>         UserHome home = (UserHome)ctx.lookup("User");
> 
> resulted in a ClassCastException on the returned object (whose class is
> $Proxy1 in the output below).  Examinging the Proxy reveals that it does
> indeed implement the interface, but the interface class was loaded in the
> wrong ClassLoader:
> 
> [Default] UserHelper ClassLoader is 'AdaptiveClassLoader(  )'
> [Default] UserHome ClassLoader is 'AdaptiveClassLoader(  )'
> [Default] $Proxy1 ClassLoader is 'sun.rmi.server.LoaderHandler$Loader@5a18ac'
> [Default]   $Proxy1 implements 'com.coretech.user.UserHome' from
> ClassLoader 'sun.rmi.server.LoaderHandler$Loader@5a18ac'
> [Default]   $Proxy1 implements 'javax.ejb.Handle' from ClassLoader
> 'sun.misc.Launcher$AppClassLoader@404536'
> 
>         So the interface is loaded by Tomcat's "AdaptiveClassLoader" but
> the Proxy coming out of JNDI is loaded by an RMI ClassLoader, which I
> assume is not aware of the AdaptiveClassLoader - despite the fact that it
> is the current ClassLoader for "UserHelper", the class executing this
> code.
> 
>         After this, I ran jBoss and Tomcat separately, and I haven't been
> able to get that to work either.  If I load the jBoss JNDI classes in
> tomcat/lib, then I get a ClassNotFoundException on "UserHome" when I use
> the code above.  This kind of makes sense, since the UserHome class is in
> the context/WEB-INF/classes directory, so you wouldn't necessarily expect
> the classes on the system classpath to be aware of it.
>         If I instead put the jBoss JNDI classes in context/WEB-INF/lib,
> then I get a ClassNotFoundException on them when I try to create the JNDI
> InitialContext.  Here's a partial trace:
> 
> javax.naming.NoInitialContextException: Cannot instantiate class:
> org.jnp.interfaces.NamingContextFactory.  Root exception is
> java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
>         at java.net.URLClassLoader$1.run(Unknown Source)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Unknown Source)
>         at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
>         at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
>         at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
>         at javax.naming.InitialContext.init(Unknown Source)
>         at javax.naming.InitialContext.<init>(Unknown Source)
> 
>         So again, it looks like the classes in context/WEB-INF/lib are
> loaded by the AdaptiveClassLoader, and here the JNDI implementation is not
> aware of AdaptiveClassLoader, despite the fact that it is the current
> ClassLoader for the code executing the call.
> 
>         Finally, if I put all my classes (User, UserHome, UserHelper,
> jBoss JNDI, etc.) in tomcat/classes and tomcat/lib, then everything
> works.  But this is pretty far from ideal - now this one app has taken
> over Tomcat instead of having the nice web app separation.
>         So I suspect I can skin this cat in several ways, and I'm looking
> for any suggestions:
> 
>  - How can I get Sun's JNDI implementation to recognize
> AdaptiveClassLoader as the current/parent ClassLoader?
> 
>  - How can I get Sun's RMI implementation to recognize Adaptive
> ClassLoader as the current/parent ClassLoader?
> 
>  - Are there any other ways to get this to work other than putting all the
> app classes on the Tomcat ClassPath?
> 
> Thanks,
>         Aaron
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

Mime
View raw message