I need to load a native library in Tomcat which will be used by web apps. I've created a wrapper class that calls System.load("path/to/library") just as described in: http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat
My class definition is similar to the one in the link:
public class FooWrapper {
public native void doFoo();
}
I am able to call doFoo() from a standalone application (which means that the native method Java_packagename_FooWrapper_doFoo(...) written in C is exported correctly). However, when I call the doFoo method from a web app I get:
java.lang.UnsatisfiedLinkError: packagename.FooWrapper.doFoo()V
I am able to get a list of the native libraries loaded by the ClassLoader using the trick described here: How do I get a list of JNI libraries which are loaded?
java.lang.reflect.Field loadedLibraries = ClassLoader.class.getDeclaredField("loadedLibraryNames");
loadedLibraries.setAccessible(true);
final Vector<String> libraries = (Vector<String>) loadedLibraries.get(ClassLoader.getSystemClassLoader());
and my native library is listed in the libraries vector, therefore the static block that calls System.load(...) is executed without any exception. However, it seems that Java cannot find a suitable function in the native library when I call doFoo() from a web app. What am I missing?