Symptoms

Deploying an ear application onto a WLS 10.3.x domain throws the following error:
Web application: "DataExtractWeb2".
java.lang.NoClassDefFoundError: org/apache/log4j/Priority
  at org.sagph.dataextract.web.DxWebStartup.loadProperties(DxWebStartup.java:101)
  at org.sagph.dataextract.web.DxWebStartup.init(DxWebStartup.java:60)
  at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:283)
  at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Priority
  at org.sagph.dataextract.web.DxWebStartup.loadProperties(DxWebStartup.java:101)
  at org.sagph.dataextract.web.DxWebStartup.init(DxWebStartup.java:60)
  at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:283)
  at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
The same application works fine on WLS 10MP1 but it is not working on WLS 10.3.x.



Cause


In WLS versions prior to 10.3.0, the log4j.jar is present in the class path and it gets loaded automatically at the time of server start. But this is not the case for WLS 10.3.0 and later releases. In WLS 10.3.0 and higher, the log4j file is no longer automatically loaded. In this case, the customer application had a dependency on log4j, and so it failed when log4j.jar was no longer automatically loaded with the WLS installation.


Solution


There are two ways to resolve, as below:

The first solution is to load the log4j jar file on startup. To accomplish this, change the value of load-on-startup tag to 1 from -1in web.xml for the servlet code that is referring to log4j. For example, in web.xml, make this change:
<load-on-startup>1</load-on-startup>

The second solution is to place the jar file in the APP-INF/lib directory of the ear file, i.e., <ear_file>/APP-INF/lib. The jar file will be loaded with the ear file and provide the jar file when the application needs it. After adding the jar file to the ear, redeploy the application and restart.

0 Comments