views:

253

answers:

2

Hi,

I am trying to initialize log4j-1.2.8 for my application by creating a listener class implemented from the ApplicationLifecycleListener of Weblogic 9.2

When I deploy the application, I am getting following exceptions:

java.lang.NoClassDefFoundError: org/apache/log4j/spi/RepositorySelector
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:338)
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:291)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:158)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at myApp.LoggerStartupService.preStart(LoggerStartupService.java:40)
at weblogic.application.internal.flow.BaseLifecycleFlow$PreStartAction.run(BaseLifecycleFlow.java:187)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.application.internal.flow.BaseLifecycleFlow$BaseAction.invoke(BaseLifecycleFlow.java:95)
at weblogic.application.internal.flow.BaseLifecycleFlow.preStart(BaseLifecycleFlow.java:53)
at weblogic.application.internal.flow.HeadLifecycleFlow.prepare(HeadLifecycleFlow.java:199)
at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:615)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:191)
at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:147)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:61)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:189)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:87)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:718)
at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1185)
at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:247)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:157)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45)
at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)

where myApp.LoggerStartupService is the class implemented from ApplicationLifecycleListener.

I checked the classpath in my scripts and its set properly for all dependencies required for log4j. Appenders & Categories are also there in the log4j.xml.

Looks like I am missing something. I would appretiate any inputs from you guys.

Thanks...

+4  A: 
java.lang.NoClassDefFoundError: org/apache/log4j/spi/RepositorySelector

This means that the in the message mentioned class is missing in the classpath during runtime (while it was available during compiletime of the calling class in question, that's the difference with ClassNotFoundException).

As this is used by Log4j itself, it's thus missing in the Log4j JAR file. The RepositorySelector javadoc learns us that it's introduced in Log4j 1.2. This would mean that there's a collision with another and older-versioned Log4j JAR file in the classpath which got precedence in classloading. It's likely somewhere hidden in one of the default classpaths of Weblogic. I don't do Weblogic, but as hinted by others, you can also try to change the classloading order, if it's supported by Weblogic. Consult its documentation.

BalusC
This has always been a problem with commonly used libraries like log4j or JSF implementation. I don't know about weblogic, in websphere there is an option to set classloader precedence from parent down to childen (container level down to ear to war level classloader) or the other way around..so it will use your deployed log4j.jar instead of container version.
DJ
I'm sorry but, no, the solution is not that simple ("clean up and replace") as you didn't take into account the specificities of a startup class (deployment, packaging, classloading, etc).
Pascal Thivent
Point taken, phrase removed.
BalusC
+1  A: 

where myApp.LoggerStartupService is the class implemented from ApplicationLifecycleListener.

Ok, so you implemented a startup class.

I checked the classpath in my scripts and its set properly for all dependencies required for log4j. Appenders & Categories are also there in the log4j.xml.

How did you setup that classpath? How did you package your startup class and where did you put it? Also, where is log4j.jar, which one do you use? Your startup class (and its dependencies) must be added to the server CLASSPATH. Is this what you did? Refer to Add startup and shutdown classes to the classpath in the official documentation for the details on how to do this.

I'd like to get confirmation of these points (but the final answer is that you should use a MANIFEST.MF in the jar of your startup class to reference third party libraries).

Pascal Thivent