0
votes

I am working on a Java/J2EE project with several webapps. I want to introduce log4j in some webapps. So I have added log4j-1.2.16.jar in WEB-INF\lib, and log4j.properties in WEB-INF\classes

As a result I get a NoClassDefFoundError :

org.apache.commons.logging.LogConfigurationException:org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@f8f541 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@f8f541 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category))
    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)

I get the same error when I try to install log4j inside Tomcat directly. (I have added the propers jars in tomcat/lib etc... like said here : http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j)

I have found that the error probably comes from a classloader problem, because of a commons.logging jar contained in a 3rd party. Indeed when I remove this jar in the 3rd party,the NoClassDefFoundError disappears. ([3rd party]/Bin/commons-logging-1.0.4.jar).

But I must not remove the jar from the 3rd party, it isused somewhere else.

Is it possible to configure commons logging to ignore log4j when loaded, or is there another way to overcome this classloader problem?

I try to use log4j-1.2.16.jar, and the 3rd party contains commons-logging-1.0.4.jar. My log4j.properties file is the default one suggested by apache in the previous link.

2

2 Answers

0
votes

You need to re-read the document you quoted.

To quote from http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j

Note: The steps described in this section are needed when you want to reconfigure Tomcat to use Apache log4j for its own logging. These steps are not needed if you just want to use log4j in your own web application. — In that case, just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application.

0
votes

Adding the following definition in your proguard. This will surely be fixed

-keep class com.amazonaws.org.apache.commons.logging.** { *; }