I wrote a webservice which i'm deploying to tomcat server. the methods of this webservice require a native library (.so) to work correctly.
I'm not sure where can i put this .so library so my deployed java webservice will find it when running in tomcat server?
also In netbeans IDE version 6.7 the IDE doesn't find any native library and i can't figure out how to tell netbeans where to find these native libraries.
any help where i should put the .so file within my webservice deployement ?
Ulf Dittmer wrote:Native libraries can only get loaded by a single classloader at any one time. For web apps that means that only a single web app can load the library; it also means that there may be problems if a web app -which uses a native library- gets reloaded.
Thanks for the reply.
So what is the best solution for loading native libraries by java web apps? is there a technique to control the one time loading of the native libraries so that even if the web app is reloaded the native libs doesn't get loaded many times?
I have another jar library that loads this native library. i include this jar in my web apps libs together with the native library. so i don't have control over the code loading the native lib. what can one do in this situation?
Ulf Dittmer wrote:One way would be to load the library from code that's guaranteed to be loaded only once. If the pertinent code was part of a jar file in TOMCAT_HOME/common/lib that would be the case. As long as it's loaded by any of the web app classloaders there'll be problems.
You mean if i place my native library in TOMCAT_HOME/common/lib directory , the Previous error will disappear ? if this is the case this means the cleanest solution to use native libraries in java web apps is to place them in the web container 'lib' folder..or am i wrong?
You mean if i place my native library in TOMCAT_HOME/common/lib directory , the Previous error will disappear ?
No. Native libraries need to be in the PATH, not in the CLASSPATH. It doesn't matter much *where* in the PATH it is, though. The Java code that *loads* the native library needs to be in a place where it's loaded by a single classloader only, and common/lib fulfills that requirement.