On Fri, 5 Apr 2002, Mark Shaw wrote:
> Date: Fri, 5 Apr 2002 16:24:28 -0800
> From: Mark Shaw <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: 'Tomcat Users List' <[EMAIL PROTECTED]>
> 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:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>