You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Richard Troy <rt...@ScienceTools.com> on 2001/11/15 21:03:06 UTC

Re: regd classloader (fwd)

Date: Thu, 18 Oct 2001 08:08:03 -0700 (PDT)
From: Craig R. McClanahan <cr...@apache.org>
Reply-To: tomcat-user@jakarta.apache.org
To: tomcat-user@jakarta.apache.org
Cc: soap-user@xml.apache.org
Subject: Re: regd classloader



On Thu, 18 Oct 2001, E B wrote:

> Date: Thu, 18 Oct 2001 10:28:27 +0100 (BST)
> From: E B <he...@yahoo.co.uk>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org, soap-user@xml.apache.org
> Subject: regd classloader
>
> Hi
> In tc4, whats the difference between "shared"
> and "common" class loader ? From the docs, I
> understand
> that from the webapp's point of view they are same.
> ie., they both give classes to all the webapps.
> Am I correct ?
>

The "shared" class loader is visible to all webapps, but NOT to Tomcat's
internal classes.

The "common" class loader is visible to all webapps AND to Tomcat's
internal classes.  A common scenario is where you wanted to use the same
JDBC driver for both a JDBCRealm implementation (so Tomcat needs access to
it) and one or more webapps.

> I want my webapp's classes to be visible and shared
> by a soap service. When I put my app's classes in
> shared dir my apache-soap's service could not find the
>
> app's classes. But it worked when I moved them to
> common/classes. So there seems to be something I am
> missing. what is it ?
>

The most likely cause is that you're trying to load classes from a "lower"
class loader in the hierarchy, which won't work.

Consider a simplified version of the hierarchy:

    Common  (package C)
      |
    Shared  (package S)
      |
    Webapp  (package W)

Now, consider what is visible to classes from each place:

* Classes in the Webapp class loader can see packages W, S, and C

* Classes in the Shared class loader can see packages S and C

* Classes in the Common class loader can see package C only.

In your scenario, it's likely that you had some class in the common
package that was trying to load your app's classes.  That won't work
unless the app's classes are also in the Common loader, OR unless the
service classes take advantage of the Context Class Loader mechanism to
get access to the webapp class loader for the current request:

  ClassLoader cl = Thread.currentThread().getContextClassLoader();
  Class clazz = cl.loadClass("W.Foo");

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>