tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Piggott" <chr...@rochester.rr.com>
Subject Class loading from within a servlet: interface definition not found
Date Fri, 28 Apr 2006 21:31:37 GMT
I have something happening with class loading from within a server, and I don't understand
it.

My servlet defines some classes called:
	org.something.server  -- the class that extends HttpServlet
	org.something.DatabaseRequestHandler -- an interface

When you make a request to the server, it figures out what handler class to load.  Then it
attempts to load it:

	Class handlerClass = Class.forName(handlerClassNameString);


QUESTION: looking at the little diagram in the Tomcat 5.5 Class Loader HOW-TO, when I do the
above (Class.forName) I am using the Webapp class loader, correct?


The handler classes are all in handlers.jar which is in $CATALINA_BASE/shared/lib.  The actual
exception that I get is:

	2006-04-28 17:05:55 StandardWrapperValve[xdb]: Servlet.service() for servlet xdb threw exception
	java.lang.NoClassDefFoundError: org/something/DatabaseRequestHandler

It took me a few minutes to realize that this was not a ClassNotFound exception, but something
else.  Reading docs I figured out that the most probably cause is that the servlet's classloader
was able to find the handler class, but then it failed to load one of the things it depended
on, specifically it was able to find handlerClass but not the interface class that it depends
on.

Trouble is: the interface .class file is right there in WEB-INF/classes/com/something/DatabaseRequestHandler.class
just like it should be.  So, I am stumped why the class loader would be able to find the handler
class in $CATALINA_BASE/shared/lib but NOT the interface that it implements which is in WEB-INF/classes.


At the suggestion of a nice gentleman on freenode, I tried turning on the -verbose:class option
in the jvm, and watched it log some interesting stuff to catalina.out.  Unfortunately it doesn't
shed any light on what is happening, beyond the exception and stack trace in the error log.
 I don't want to post the whole stack trace (unless someone thinks it would help to see it)
but I will say that it includes catalina.loader.WebappClassLoader as well as catalina.loader.StandardClassLoader

--Chris




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message