tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Hirsh <>
Subject Shared library jni under tomcat
Date Tue, 20 Nov 2018 06:03:22 GMT
I am running Tomcat 8.0.32 on LInux, and trying to use a jni library under
tomcat, and am hitting a wall.

First I found that only one instance of the native library can be loaded so
the library needs to live in shared/lib for general use.

Then in order to load the native library I found documentation that I both
needed to load the native library from a bootstrap jar that also lives in
shared/lib and that the jar be loaded with the common clasloader

So I have my code working to do all that.  And if I make a call from the
bootstrap jar to the first native method it works.
But when I try to access the native method from my application code I get
an error "java.lang.UnsatisfiedLinkError:".

I believe that is because the native library has been loaded with the
URLClassLoader and the application is loaded with the WepappClassLoader.
Although I also read that the classloaders are hierarchical, and should go
up the chain to find classes.

I have verified that the URLClassLoader used to load the bootstrap jar is
the same as the parent loader of the application (with .equals())

I did read an ancient thread (2006) that kind of described the problem I am
having, and the last post there indicated that the solution is "to touch
each class that uses native methods (from the loader that loaded the native
library) , forcing the classes to be loaded".  But I don't know how to
'touch' a java class.  And my classes that use native methods are part of
the application and could not be loaded by the URLClassLoader in any case.
Or even if that post is (still) relevant.

I have run out of ideas on what to do or test next.  I've been through doc
and many posts on stackoverflow on this topic, and cannot find anything to

 Any suggestions would be most welcome.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message