• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4j in Weblogic - ClassNotFoundException please help

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure the log4j library in your application is not being loaded. Can you post the entire stack trace ?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try adding log4j.jar to the classpath. if you are using logkit.jar, add that as well to classpath.
 
Guy Belpa
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to say "prefer application level classes over system level classes." ???
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this -> https://coderanch.com/forums/posts/list/478489#2154062
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bala wrote:Something like this -> https://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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam bartl wrote:

Deepak Bala wrote:Something like this -> https://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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam bartl wrote:

sam bartl wrote:

Deepak Bala wrote:Something like this -> https://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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic