tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Echerer <m...@tngtech.com>
Subject Re: Class loading from within a servlet: interface definition not found
Date Mon, 01 May 2006 12:49:35 GMT
David Smith wrote:
> most likely the shared classloader instead.  If possible, move the
> handler.jar from shared/lib to WEB-INF/lib of your webapp and the
> problem should go away.
>>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.

What you are trying to do won't work or at least is asking for much
classloading trouble.
Its basically the same as if you try to put a jdbc jar in common/lib AND
in WEB-INF/lib or put the servlet api which is included by Tomcat into
WEB-INF/lib again.
Bad idea and sometimes caused by unwanted glitches in ant build.xmls as
it is convenient to put all .jars into the .war that were required for
the build, eventhough the are harmful when deployed.

Even if the classloader would find your classes and interfaces if you
rebundle your jars you'll run into problems (class cast exceptions) as
soon if you try to cast objects loaded by two different classloaders
later on. E.g. you have created a Handler class by the shared
classloader and later on cast in your webapp by using the webapp
classloader to use it.
Remember: for instanceof to be true it's not enough to have the same
class, two objects have to be loaded by the same classloader, too.

Repackage your code, use the same classloader, or as David said put
everything into WEB-INF/lib.

Cheers,
Michael


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


Mime
View raw message