tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: Design question: common/lib --> WEB-INF/lib
Date Sat, 06 Apr 2002 03:35:17 GMT


On Fri, 5 Apr 2002, Mark Shaw wrote:

> Date: Fri, 5 Apr 2002 16:24:28 -0800
> From: Mark Shaw <MShaw@centricasoftware.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: 'Tomcat Users List' <tomcat-user@jakarta.apache.org>
> Subject: RE: Design question: common/lib --> WEB-INF/lib
>
> > ClassLoader webappLoader =
> >   Thread.currentThread().getContextClassLoader();
> > Class webappClass = webappLoader.loadClass("com.mycompany.MyClass");
>
> > This works because the container (Tomcat in this case) always sets the
> thread context class loader to the one
> > for the webapp being executed on the current request thread -- therefore,
> the classes in /WEB-INF/classes and
> > /WEB-INF/lib are visible via this class loader, even though the class
> containing the above code is loaded
> > from somewhere else.
>
> Craig,
> I still get a ClassNotFoundException.  I've implemented a Realm that extends
> RealmBase.  My code that references the webapp class is in getPassword().
> I'm assuming that this is called from a request thread?
> What's interesting is that loadClass() doesn't throw the exception, but then
> I try to call webappClass.newInstance(), a ClassNotFoundException is thrown?
>

The thread context class loader stuff works for application-level (i.e.
Filter, Servlet, and JavaBean) access to the webapp class loader.  From
inside Catalina (which is where a Realm executes), different rules apply.
In particular, you can acquire a reference to the corresponding webapp
class loader like this:

  ClassLoader webappClassLoader =
    getContainer().getLoader().getClassLoader();

> Any ideas?  Thanks.
> -Mark
>

Craig


--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message