Note that there are some explanatory texts on larger screens.

plurals
  1. POShared native library in Tomcat UnsatisfiedLinkError
    text
    copied!<p>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: <a href="http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat" rel="nofollow noreferrer">http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat</a></p> <p>My class definition is similar to the one in the link:</p> <pre><code>public class FooWrapper { public native void doFoo(); } </code></pre> <p>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:</p> <pre><code>java.lang.UnsatisfiedLinkError: packagename.FooWrapper.doFoo()V </code></pre> <p>I am able to get a list of the native libraries loaded by the ClassLoader using the trick described here: <a href="https://stackoverflow.com/questions/1007861/how-do-i-get-a-list-of-jni-libraries-which-are-loaded">How do I get a list of JNI libraries which are loaded?</a></p> <pre><code> java.lang.reflect.Field loadedLibraries = ClassLoader.class.getDeclaredField("loadedLibraryNames"); loadedLibraries.setAccessible(true); final Vector&lt;String&gt; libraries = (Vector&lt;String&gt;) loadedLibraries.get(ClassLoader.getSystemClassLoader()); </code></pre> <p>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? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload