aspose file tools*
The moose likes BEA/Weblogic and the fly likes Log4j in Weblogic - ClassNotFoundException please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Log4j in Weblogic - ClassNotFoundException please help" Watch "Log4j in Weblogic - ClassNotFoundException please help" New topic
Author

Log4j in Weblogic - ClassNotFoundException please help

Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41


Hi all,

I develope a web based application using Jdeveloper+struts

For logging i used log4j

My webserver is Oracle Weblogic.

But when I install and start the web application using
weblogic console it gives an error,


java.lang.ClassNotFoundException: org.apache.log4j.Category


My libries in WEB-INF/lib as follows,

antlr.jar
commons-beanutils.jar
commons-digester.jar
commons-fileupload-1.0.jar
commons-validator.jar
dom4j-1.6.1.jar
dwr.jar
jakarta-oro.jar
struts.jar
log4j-1.2.8.jar


Do you have any idea?
Do you need any more information please tell.
Thanks in advace.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Are you sure the log4j library in your application is not being loaded. Can you post the entire stack trace ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Andy Kay
Greenhorn

Joined: Oct 26, 2009
Posts: 29
Try adding log4j.jar to the classpath. if you are using logkit.jar, add that as well to classpath.


http://ananthkannan.blogspot.com
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41
entire stack trace :



org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@116e2a2 for org.apache.
commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by org.apache.commons.logging.LogConfigurationException: No suitabl
e Log constructor [Ljava.lang.Class;@116e2a2 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)
at org.apache.struts.action.ActionServlet.<clinit>(ActionServlet.java:226)
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 java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:223)
at weblogic.servlet.internal.WebComponentContributor.createServletInstance(WebComponentContributor.java:247)
at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:255)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:64)
at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:58)
at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:48)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:521)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1893)
at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1870)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1790)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2999)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1371)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:468)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:117)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:635)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212)
at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:16)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:162)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:569)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:140)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:106)
at weblogic.deploy.internal.targetserver.operations.StartOperation.doCommit(StartOperation.java:143)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:323)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:820)
at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1227)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:436)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:163)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:181)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:12)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:67)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@116e2a2 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.
NoClassDefFoundError: org/apache/log4j/Category)
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41
i heard that because the commons-logging.jar is apparently in the system classpath, due to the way Java classloader delegation works, any log4j classes at the web application level are not visible to the logger factory by default.

Anyone know how to overcome this?

Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41
Is there a way to say "prefer application level classes over system level classes." ???
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

because the commons-logging.jar is apparently in the system classpath, due to the way Java classloader delegation works, any log4j classes at the web application level are not visible to the logger factory by default.


hehehe ! This is a classloading problem. The reason I laugh is because I know you are in for a ride if the problem cannot be resolved easily. You can resolve this by placing log4j in the system classpath if that is allowed (or if that is even the real problem). The error occurs because of a design by which classloader will ask their parents first if the class can be resolved. There is also another model called child first. Depends on which server you are using, but most of them use the parent first model.

There is a big and detailed article about this -> http://articles.qos.ch/classloader.html

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

prefer application level classes over system level classes


Yes that is also a solution. But one that I do not like since an exception is thrown by an internal classloader to achieve the end result. Nothing wrong with that but it sounds a little dirty to me. You can use either solution to solve the problem. But diagnose the side effects carefully before you release the solution. Regression test it with all applications since you are altering class loading behaviour.
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41
Thank you very much Deepak Bala !

But did you answer my problem? I did not get it. Please explain if you can.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

But did you answer my problem? I did not get it. Please explain if you can.


ok here goes

1. You may use the "prefer application level classes over system level classes." option for commons logging jar.
2. You can move log4j to the system class path.

Both options may have side effects. Prefer application classes might throw off code that expects WL's version of the class. Unlikely to happen but it is a possibility.

Moving log4j to the system classpath will affect other applications that were relying on their own version of log4j. They will have the same problem with log4j that you have with commons-logging.

Analyze carefully before you go for a solution
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41


Created a new file call "weblogic.xml" in WEB-INF


<?xml version="1.0" encoding="ISO-8859-1"?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

</weblogic-web-app>


working fine now!
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Glad to hear that. Test your application fully in order to find out if it bombs somewhere else because of this change.
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41
Thanks, what kind of issue/"BOMB" you mean?

prefer-web-inf-classes
The <prefer-web-inf-classes> element, if set to true, will cause classes located in the WEB-INF directory of a Web application to be loaded in preference to classes loaded in the application or system classloader. The default value is false. A value specified in the console will take precedence over a value set manually.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Something like this -> http://www.coderanch.com/forums/posts/list/478489#2154062
sam bartl
Ranch Hand

Joined: Oct 29, 2010
Posts: 44
Deepak Bala wrote:Something like this -> http://www.coderanch.com/forums/posts/list/478489#2154062


I am having the same problem , mine is a ear file , the solution weblogic.xml with preferred-web-inf-classes is suggested for a war file but what about ear file , I tried adding webloigc-application.xml but did not help , please advice me please help me , appreciate all your help.
sam bartl
Ranch Hand

Joined: Oct 29, 2010
Posts: 44
sam bartl wrote:
Deepak Bala wrote:Something like this -> http://www.coderanch.com/forums/posts/list/478489#2154062


I am having the same problem , mine is a ear file , the solution weblogic.xml with preferred-web-inf-classes is suggested for a war file but what about ear file , I tried adding webloigc-application.xml but did not help , please advice me please help me , appreciate all your help.



here more description of m problem,

this is the exception I get



my weblogic-application.xml has the follwoing entries,



I started getting this exception after I added opensaml.
I think this is just classloading issue , Weblogic gurus please help me.

sam bartl
Ranch Hand

Joined: Oct 29, 2010
Posts: 44
sam bartl wrote:
sam bartl wrote:
Deepak Bala wrote:Something like this -> http://www.coderanch.com/forums/posts/list/478489#2154062


I am having the same problem , mine is a ear file , the solution weblogic.xml with preferred-web-inf-classes is suggested for a war file but what about ear file , I tried adding webloigc-application.xml but did not help , please advice me please help me , appreciate all your help.



here more description of m problem,

this is the exception I get



my weblogic-application.xml has the follwoing entries,



I started getting this exception after I added opensaml.
I think this is just classloading issue , Weblogic gurus please help me.




I was able to resolve the problem by adding org.opensaml in prefer-application-packages, it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4j in Weblogic - ClassNotFoundException please help