Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NoClassDefFound error

Status
Not open for further replies.

flowcontrol

Programmer
Oct 16, 2002
86
US
I'm coming back to a project after not working on it for several weeks. I created a new servlet for my web-app and "registered" it in the app's deployment descriptor. I reloaded the app using Tomcat Manager. When I try to invoke the servlet, I get a NoClassDefFound exception. The class exists, so I'm thinking that maybe two different class loaders are involved and thus one class can't find the other. But, that's just a WAG. I was running tomcat with -Dsecurity.manager when the error occurred, but I took that out (and still get the error). Does anybody have ANY ideas??

Here is part of the error message:
Code:
[b]exception[/b]

javax.servlet.ServletException: Error allocating a servlet instance
     org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
...

[b]root cause[/b]

java.lang.NoClassDefFoundError: com/mycompany/dept/MyStats (wrong name: MyStats)
     java.lang.ClassLoader.defineClass0(Native Method)
     java.lang.ClassLoader.defineClass(ClassLoader.java:539)
     java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
Here is the deployment descriptor (I used different tokens for servlet-name, servlet-class, and servlet-mapping to make it clear what the error message was referring to):
Code:
<servlet>
   <servlet-name>
      Stats
   </servlet-name>
   <servlet-class>
      com.mycompany.dept.MyStats
   </servlet-class>
</servlet>

<servlet-mapping>
   <servlet-name>
      Stats
   </servlet-name>
   <url-pattern>
      /GetStats
   </url-pattern>
</servlet-mapping>

 
Sounds like your package names are incorrect at compile time - its not tomcat.

com/mycompany/dept/MyStats (wrong name: MyStats)

Make sure that when you compile MyStats.java it is in the correct directory structure (ie com/mycompany/dept) and that you compile it as :

javac com/mycompany/dept/MyStats.java

and that the code has the correct package declaration , ie

package com.mycompany.dept;

--------------------------------------------------
Free Database Connection Pooling Software
 
You're right on the mark. I figured it out eventually. Java 2 does not allow classes in the default package to be imported. I had failed to put a package declaration at the top of the file.

Sheesh! How could I have forgotten that?

Thanks sedj!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top