#145 classpath problem inside tomcat 3.2.1

open
nobody
General (151)
5
2003-11-11
2003-11-11
Anonymous
No

When I placed BshServlet in the same war file as my
application (so bsh-2.0b1.jar ended up in the same dir as
my other server side jars webapp/web-inf/lib). The
BshServlet was unable to 'see' any of the classes loaded
by the servlet's classloader.

When I dumped
bsh.servlet.BshServlet.class.getClassLoader() and did
the same with one of my other servlets I determined
that both servlets were being loaded by the same
classloader (which is good!) but when I placed some
debugging code in the BeanShell code I discovered
that ClassManagerImpl.plainClassForName(String)
seemed to return the default java VM classloader not
Tomcat's adaptive classloader.

Not completely sure that I know what I was doing ;)

But the following fixed it for me..

public Class plainClassForName( String name )
throws ClassNotFoundException{
// Requires JDK 1.2+
// GRF: When dealing with servlets this screws us up!
// GRF: ClassLoader contextClassLoader =
// GRF: Thread.currentThread().getContextClassLoader
();
// GRF: So replaced by
ClassLoader contextClassLoader = null;
if ( contextClassLoader != null )
return Class.forName( name, true,
contextClassLoader );
else
return super.plainClassForName( name );
}

Anyway... this got me moving ahead... Whether this is a
bug may be up for debate. I just know that I had to do
this to get my classes visible.

Discussion