Classloader issues loading library in Tomcat 6
I am trying to write a new listener for Jira and I've encountered an issue that I would really appreciate some help and guidance with.
Background We are running Jira 4.2.2 Enterprise WAR under Apache Tomcat. This includes the following jar files under webapps/jira/WEB-INF/lib:
* slf4j-api-1.5.8.jar
* slf4j-log4j12-1.5.8.jar
We have a simple class that runs as a plugin. It receives events and based on the type of event, does some work. This class uses slf4j for logging and works as expect开发者_JAVA技巧ed. The class is packaged into a jar and deployed under webapps/jira/WEB-INF/lib and used from there. We can add this as a listener, configure it and see init messages in the log. All logging happens through slf4j and works.
When we try and add functionality to our plugin from a 3rd party library, we receive the following exception: com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
As slf4j is available and used by the class that we call this 3rd party library from, I do not understand what I am doing wrong or how to make this available at the time that the call is made.
Working case
In our code, we create a logger as follows:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.3rdparty.login;
public class JiraSampleListener extends AbstractIssueEventListener implements IssueEventListener {
private final static Logger logger = LoggerFactory.getLogger(JiraSampleListener.class);
.
.
.
We can then use this by calling
logger.warn("MESSAGE")
The expected message appears in our logs.
Error case
As soon as we add the following code to this class, we receive the attached exception:
newThing = new 3rdPartyClass("name of thing");
Exception
com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
Any advice on resolving this or pointers to what I'm doing wrong here would be greatly appreciated!
A fuller view of the exception follows...
2011-01-19 05:30:51,016 main ERROR [com.atlassian.jira.ComponentManager] Error occurred while starting component 'com.atlassian.jira.event.DefaultListenerManager'. com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:148) at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:111) at com.atlassian.util.concurrent.ResettableLazyReference.get(ResettableLazyReference.java:89) at com.atlassian.jira.event.DefaultListenerManager$Listeners.start(DefaultListenerManager.java:93) at com.atlassian.jira.event.DefaultListenerManager.start(DefaultListenerManager.java:38) at com.atlassian.jira.ComponentManager.quickStart(ComponentManager.java:256) at com.atlassian.jira.ComponentManager.start(ComponentManager.java:212) at com.atlassian.jira.upgrade.ConsistencyLauncher.launchConsistencyChecker(ConsistencyLauncher.java:63) at com.atlassian.jira.upgrade.ConsistencyLauncher.contextInitialized(ConsistencyLauncher.java:42) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:785) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:519) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:581) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at 3rd.party.3rdPartyClassDefaultImpl.(3rdPartyClassDefaultImpl.java:101) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at 3rd.party.3rdParty.(3rdParty.java:107) at 3rd.party.3rdParty.(3rdParty.java:83) at 3rd.party.3rdParty.(3rdParty.java:67) at my.organisationlisteners.JiraSampleListener.init(JiraSampleListener.java:36) at com.atlassian.jira.event.ListenerFactory.getListener(ListenerFactory.java:33) at com.atlassian.jira.event.DefaultListenerManager$Listeners.loadListeners(DefaultListenerManager.java:126) at com.atlassian.jira.event.DefaultListenerManager$Listeners.create(DefaultListenerManager.java:71) at com.atlassian.jira.event.DefaultListenerManager$Listeners.create(DefaultListenerManager.java:66) at com.atlassian.util.concurrent.ResettableLazyReference$InternalReference.create(ResettableLazyReference.java:143) at com.atlassian.util.concurrent.LazyReference$Sync.run(LazyReference.java:316) at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:142) ... 32 more Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 46 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at
3rd.party.3rdPartyClassDefaultImpl.(3rdPartyClassDefaultImpl.java:101) at
java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at
3rd.party.3rdParty.(3rdParty.java:107) at 3rd.party.3rdParty.(3rdParty.java:83) at
3rd.party.3rdParty.(3rdParty.java:67) at
It means that your class 3rdPartyClassDefaultImpl
cannot find LoggerFactory
. Is this third party library located under CATALINA_HOME\lib ? if so it means that it's loaded by "Common classloader" (classloaders in tomcat) and all required classes (3rdPartyClassDefaultImpl, LoggerFactory
) are searched in it's or parent's class repositories and cannot be found.
one of the posible solutions would be to place thirparty.jar under web-inf/lib
or to move slf4j and log4jwrapper to CATALINA_HOME\LIB
精彩评论