I have a webapp running under Tomcat 3.2.1 that needs to make JNI calls in order to access data and methods in legacy C++ code. A servlet is loaded on startup of the webapp
You can't load the same native library twice.
Put the class in a jar file under <tomcat>/lib/, it will be shared over all wars.
I had this problem and I solved it:
Problem:
The problem is due to some configurations of your application server which cause to create more than one war or ear files and consequently it creates more than one deployed files. These deployed files attempt to have a concurrent access to your native library which loaded in a static block.
Solution:
java processes from task managerjboss-eap-6.4.0\standalone\configuration and open standalone.xml filestandalone.xml , delete all the deployments tag (Don't worry, when you rerun the application server, it inserts this tagjboss-eap-6.4.0\standalone\deployments and delete all deployed
files and war files. (You can backup your war files)explodedCopy the DLLs to temporary files in a temporary directory before loading them. Delete the files when you are done. This way you can ensure that the same DLL is not loaded twice.
See the section I'm encountering classloader problems when using JNI under Tomcat on the Tomcat HowTo wiki (http://wiki.apache.org/tomcat/HowTo)