tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Solomon Gorlick <Solo...@abilizer.com>
Subject NoClassDefFoundError with servlet child/parent in different jars in lib directory
Date Wed, 22 Aug 2001 00:50:02 GMT
Hi,

I am running tomcat on NT 4.0 and am having an issues with a parent/child
servlet situation.  Particularly, I have two simple servlets - ServletParent
- in one jar in the lib directory for my application - and another servlet -
ServletChild (which extends ServletParent) - in a different jar also in the
lib directory.  I have the following set up in web.xml:

	<servlet> 
		<servlet-name>parent</servlet-name> 
		<servlet-class>paw.system.ServletParent</servlet-class> 
	</servlet>	
	<servlet> 
		<servlet-name>child</servlet-name> 
	
<servlet-class>com.abilizer.testing.ServletChild</servlet-class> 
	</servlet>
	<servlet-mapping> 
		<servlet-name>parent</servlet-name> 
		<url-pattern>/parent</url-pattern> 
	</servlet-mapping>	
	<servlet-mapping> 
		<servlet-name>child</servlet-name> 
		<url-pattern>/child</url-pattern> 
	</servlet-mapping>

Code for the servlets is pretty simple - I have removed any static
initializers, etc for testing (thanks to a previous post).  Here is the code
for ServletChild.  The parent is almost the same (different package,
comments and name).

package com.abilizer.testing;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletChild extends paw.system.ServletParent
{
    
    public void init() throws ServletException{
        System.out.println("ServletChild INITING" );
    }
    
    public void service( HttpServletRequest  request, HttpServletResponse
response )
    throws ServletException, java.io.IOException
    {
        System.out.println("ServletChild SERVICE" );
        
        try{
            PrintWriter out = response.getWriter();
            out.println("Top of ServletChild SERVICE");
            out.flush();
            out.close();
        }
        catch( IOException e ){
            e.printStackTrace();
        }
        
        
    }
    
}


If I start the server and go to http://blah.blah.com/parent in the browser,
I get expected output.  However, if I instead go to
http://blah.blah.com/child, I get this error:

Error: 500
Location: /child
Internal Servlet Error:
java.lang.NoClassDefFoundError: paw/system/ServletParent
	at java.lang.ClassLoader.defineClass0(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
	at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
	at
org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.j
ava:446)
	at
org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoad
er.java:174)
	at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
	at
org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
	at org.apache.tomcat.core.Handler.service(Handler.java:254)
	at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
	at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
	at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
	at java.lang.Thread.run(Thread.java:484)

Curiously, if I instead move the ServletChild into the same package (and
jar) as the ServletParent (and change the web.xml file), it seems to work
fine.
Alternatively, if I extract the classes from the .jar file that contains the
ServletChild and put these classes in /WEB-INF/classes (and leave the
parent's jar alone), it also seems to work fine.  
As a final alternative, if I modify the CLASSPATH in tomcat.bat to include
the ServletParent's jar, it also seems to work fine.

Is there something interesting going on with the class loader that I don't
understand?  Shouldn't it be okay if a (servlet) class in one jar is
dependent on a class in another, and both of these jars are in the
/WEB-INF/lib directory?

Thanks for any help.

Solomon



Mime
View raw message