1

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.

I've followed these steps:

http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat

and placed a singleton class (as a jar) with the static { System.loadLibrary() } call under ${TOMCAT}/lib. When my Tomcat webapp accesses this Singleton, it still throws the error

UnsatisfiedLinkError: Native Library ${TOMCAT}\lib\Native.dll already loaded in another classloader

Is this wrong in thinking that Tomcat's common classloader is loading this class, instantiating it (as per: http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html) and then passing the reference to the webapp thus bypassing the webapp classloader?

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?

Any discussion much appreciated.

4

1 回答 1

0

按照此链接卸载 dll:

http://www.codethesis.com/blog/unload-java-jni-dll

网络存档版本

我在 Tomcat 上运行我的 Web 应用程序进行了尝试,它可以工作!

简而言之,我从我的自定义类加载器使用反射加载的类中调用 System.loadLibrary。然后这个类被垃圾收集器删除。

于 2014-09-22T21:56:42.547 回答