![]() |
![]() |
||||
This page shows errors where an java.lang.NoClassDefFoundError exception is thrown and how to fix them.
Table of Contents
java.lang.NoClassDefFoundError: Could not initialize class (some class, such as gwtserver.upload.UploadAction) at org.apache.jsp.a_jsp._jspService(a_jsp.java:72) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at sun.reflect.GeneratedMethodAccessor593.invoke(Unknown Source)
This exception is thrown when initialization of a class fails, unfortunately it can be quite time consuming to find the cause.
An example is that an exception is being thrown and silently ignored by the initializer or static initialization area of code in the class or a class which it relies on, preventing this class to be properly initialized.
A common cause is that log4j is being used, but not being correctly initialized. log4j is known to silently hide the error, rather than outputing it to the System.log. For example, the gwtupload serlet fails (up to version 1.0.1 anyway) with the message "INFO: Marking servlet uploadServlet as unavailable". By attempting to instantiate the class using a simple JSP test file, you can see the NoClassDefFoundError, and then looking into it further, it is caused by log4j not being initialized, due to an invalid path for the log file.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.struts.taglib.html.HtmlTag sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ...
This exception occurs due to an inability to initialize the Struts HtmlTag tag. Depending on which tag library is used first, different struts tags may also report they cannot initialize. The first one referenced is the one that throws the exception.
The real error is that while trying to initialize, Struts tried to attach to a Logger and the Logger was not initialized, usually this is a log4j properties file error.
SEVERE: Servlet.service() for servlet jsp threw exception java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager at org.apache.log4j.Logger.getLogger(Logger.java:85) at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229) at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529) at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351) at org.apache.struts.util.MessageResources.<clinit>(MessageResources.java:57) at org.apache.struts.taglib.html.HtmlTag.<clinit>(HtmlTag.java:48) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ...
This is caused by log4j not being correctly initialized.