title: Classloader issues loading library in Tomcat 6
body: <p>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.</p>
  
  <p><strong>Background</strong>
  We are running Jira 4.2.2 Enterprise WAR under Apache Tomcat. This includes the following jar files under webapps/jira/WEB-INF/lib:</p>
  
  <pre><code>* slf4j-api-1.5.8.jar
  * slf4j-log4j12-1.5.8.jar
  </code></pre>
  
  <p>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 expected. 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.</p>
  
  <p>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</p>
  
  <p>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.</p>
  
  <p><strong>Working case</strong></p>
  
  <p>In our code, we create a logger as follows:</p>
  
  <pre><code>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);
      .
      .
      .
  </code></pre>
  
  <p>We can then use this by calling</p>
  
  <pre><code>logger.warn("MESSAGE")
  </code></pre>
  
  <p>The expected message appears in our logs.</p>
  
  <p><strong>Error case</strong></p>
  
  <p>As soon as we add the following code to this class, we receive the attached exception:</p>
  
  <pre><code>newThing = new 3rdPartyClass("name of thing");
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <blockquote>
    <p>com.atlassian.util.concurrent.LazyReference$InitializationException:
    java.lang.NoClassDefFoundError:
    org/slf4j/LoggerFactory</p>
  </blockquote>
  
  <p>Any advice on resolving this or pointers to what I'm doing wrong here would be greatly appreciated!</p>
  
  <p>A fuller view of the exception follows...</p>
  
  <pre>
  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
  </pre>