tags:

views:

762

answers:

2

java.lang.NoClassDefFoundError: happens sporadically on Resin sever start up

This is on Resin 3.0.21 Using Java 1.5 on Linux machine...

I have a servlet defined on the web.xml to load the log4j.properties. This is thrown when the servlet is trying to load on start up..

log4j-init: init log4j:ERROR Could not instantiate class [org.apache.log4j.DailyRollingFileAppender]. java.lang.ClassNotFoundException: org.apache.log4j.DailyRollingFileAppender [java.lang.NoClassDefFoundError: org/apache/log4j/FileAppender] at com.caucho.loader.DynamicClassLoader.loadClass(DynamicClassLoader.java:1264) at com.caucho.loader.DynamicClassLoader.findClass(DynamicClassLoader.java:1149) at com.caucho.loader.DynamicClassLoader.loadClass(DynamicClassLoader.java:1072) at com.caucho.loader.DynamicClassLoader.loadClass(DynamicClassLoader.java:1021) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at org.apache.log4j.helpers.Loader.loadClass(Loader.java:160) at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:309) at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:112) at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:620)

+1  A: 

Most likely, the file log4j.jar is found on the classpath twice, causing Classpath problems. If log4J gets loaded twice, once in the Web Application and once in Resin, then you can get this kind of confusion. Assuming log4j is already present in Resin, if it is also present in your web application's classpath (lib directory), then try removing it from your application's lib directory.

Eddie
A: 

It might be not "start" but "restart" situation.

Some classes of log4j are not unloaded on app's shutdown and next (re)start will cause the situation with twice entry (look at Eddie's post), if log4j loaded in webapp. The solution is to put log4j into resin's lib/ directory.

Vugluskr