Metawerx Java Hosting Small Logo

Debug Your App - java.lang.NoClassDefFoundError

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 org.apache.struts.taglib.html.HtmlTag

Submitter: Neale Rudd
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.

  • You should see another java.lang.NoClassDefFoundError error higher in the log saying the class org.apache.log4j.LogManager could not be initialized.
  • You should also see a java.security.AccessControlException or a log4j error of some type, even higher up, complaining that the log file could not be written.
  • Fix the log error first, then restart the application. This error should no longer appear.

java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager

Submitter: Neale Rudd
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.

  • You should also see a java.security.AccessControlException or a log4j error of some type, even higher up, complaining that the log file could not be written.
  • Fix the log error first, then restart the application. This error should no longer appear.
navigation
metawerx specific
search
Share
tools
help

referring pages
Valid XHTML 1.0 Transitional

Share