title: Tomcat DLL already loaded in another classloader
body: <p>I have a DLL that provides access to Window's LoadLibrary and FreeLibrary (to get around Java not being able to unload it). I need this DLL to persist between each webapp as it cannot be loaded twice.</p>
  
  <p>I've followed these steps:</p>
  
  <p><a href="http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat" rel="nofollow">http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat</a></p>
  
  <p>and placed a singleton class (as a jar) with the <code>static { System.loadLibrary() }</code> call under ${TOMCAT}/lib. When my Tomcat webapp accesses this Singleton, it still throws the error </p>
  
  <p><code>UnsatisfiedLinkError: Native Library ${TOMCAT}\lib\Native.dll already loaded in another classloader</code></p>
  
  <p>Is this wrong in thinking that Tomcat's common classloader is loading this class, instantiating it (as per: <a href="http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html" rel="nofollow">http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html</a>) and then passing the reference to the webapp thus bypassing the webapp classloader?</p>
  
  <p>Is there a way to tell Tomcat to instantiate my singleton (forcing the common classloader to do it) and then provide that instance to satisfy my webapp's dependency?</p>
  
  <p>Any discussion much appreciated.</p>