tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Verbist <>
Subject Problem with loading classes dynamically, new objects can't "see" things in webapp.
Date Tue, 11 Sep 2001 11:04:06 GMT
Hi all.

I hope I'm not being too dumb here.

My servlet code wants to load classes dynamically at runtime.  Instances of
these classes will call back into the servlet code.

So, my server.xml looks like this:

    <Context path="/prosumer"

with all the class files under ...\webapp\WEB-INF\classes

Mostly it works fine.
However when I try to execute this line:

    Class c = Class.forName("com.psl.test.customtags.ProsumerTestTag");

where ProsumerTestTag is defined thusly:

    public class ProsumerTestTag implements CustomTag {

tomcat keels over with:

java.lang.NoClassDefFoundError: com/psl/customtags/CustomTag
	at java.lang.ClassLoader.defineClass0(Native Method)
	at java.lang.ClassLoader.defineClass(
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.ClassLoader.loadClassInternal(
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(

left in the jvm.stderr

I guess it can't find the "CustomTag" that ProsumerTestTag implements.
However com/psl/customtags/CustomTag *realy is* in the webapp.

I'm running tomcat 3.2.2 as a service on a Win2k server box, and if I add
the whole of the webapp code to the classpath for the jvm for tomcat by
editing the for jk_nt_service.exe, then the whole
thing works.  However this workaround seems to be suboptimal.

My question is why can't a class loaded by Class.forName() see things in
webapp/WEB-INF/classes, only things in the regular JVM classpath, when the
rest of the webapp can see things in the webapp/WEB-INF/classes?

I guess my call to Class.forName() is creating a different context for the
new class to what is created for the rest of the servlet, but is there some
way I can resolve the differences?

Thanks very much.


View raw message