How to resolve Tomcat java.lang.NoClassDefFoundError exception

I’m recently working on a large online website and using Tomcat in development phase, I broke the tomcat so that I got the NoClassDefFoundError exception. Here is the stack trace of NoClassDefFoundError.

ClassNotFoundException: com.sap.mw.jco.rfc.MiddlewareRFC
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at SecurePaymentAjaxData.doPost(SecurePaymentAjaxData.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

When ClassNotFoundException is occurring, this is to say that the class loader is not able to find the class binary file in webapp classpath (the jars in mywebapp/WEB-INF/lib). Same situation also happens to NoClassDefFoundError. If you have same issue it is strongly recommended you follow the below:

  1. Check whether or not the required Jar is listed in WEB-INF/lib folder of your WAR? If not add it.
  2. If the Jar has included in classpath, check whether the class exists in this Jar package.
  3. Try to restart tomcat.
Rate article
ASJAVA.COM
Add a comment

Your email address will not be published. Required fields are marked *

*

code

  1. Anuja

    What does it mean: If the Jar has included in classpath, check whether or not the class within the JAR.

    Reply
    1. admin author

      if your Jar has included in classpath(or have existed in WEB-INF/lib) and you also got NoClassDefFoundError exception, perhaps the class didn’t include within the Jar. so you need check it.

      For example. we have got NoClassDefFoundError FileUtil exception, commonly FileUtil.class should be within apache common-io.jar. first of all you need to check that common-io.jar has really existed WEB-INF/lib directory(tomcat lib dir), next, if you still got the NoClassDefFoundError FileUtil exception, you may check the class FileUtil is really included within Jar common-io.jar.

      Reply
  2. aladeck

    I don’t have same problem.
    my problem:
    Normal, system run without exception “java.lang.NoClassDefFoundError”. But some time, we receive this exception.
    After restart Tomcat, system is returned to normal state.
    I think our system has problem with memory.

    Reply
  3. Gonzalo Oviedo

    See StackOverflow, they are amazing, you have to do with Eclipse: go to Properties of the WebProject and go to Assembly. Put your dependency project there!.

    Reply