Shared JNI library (.so) in Tomcat - UnsatisfiedLinkError

system.loadlibrary unsatisfiedlinkerror
java lang unsatisfiedlinkerror can t load library
unsatisfiedlinkerror jni
system.loadlibrary android
exception in thread main'' java lang unsatisfiedlinkerror
java load native library
java.lang.unsatisfiedlinkerror no in java.library.path linux
spring boot load native library

I have a JNI library (.so) shared between two web applications deployed in Tomcat7. I am loading the library using the System.loadLibrary only once in the first web application that is being deployed and then in the second I'm checking if it already was loaded to not load anymore (I tried loading it in both and I got UnsatisfiedLinkError - library was loaded by another classloader). I can make any call to the native library in the first application, but in the second one I get UnsatisfiedLinkError with the method name that I am trying to call.

I am running out of ideas of what I can do. Any ideas? I tried most of the solutions on SO. Thank you.

EDIT Yes, I tried adding the library in the tomcat lib folder and loading it from there. Initially it was in the bin folder and the same issue occurs.

Yes, this will happen when you try to load the library that has already loaded my another web application. Tomcat, uses separate class loaders for each of the web application, and it wont allow you load a same native library more than once to JVM via another class loader

Move any share jar files if any that consumes JNI from you Add the system path to sharedlib ,

export LD_LIBRARY_PATH=/path/to/whereyourlinklibrary

Write a simple class like this which enables you to load your shared library when tomcat starts. Just compile this class and drop it in tomcat lib folder

package msm;
public class DLLBootstrapper {

     static {

     public static void main(String args[]) {


you can now load this class from any of your web application ( probably in startup listener)


Good to go!

java.lang.UnsatisfiedLinkError: no dll in java.library , When you load native libraries like .so on Linux or .dll on Windows using System. loadLibrary() Java looks for those shared libraries in both PATH environment� 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.

Have you tried putting shared JNI library just inside the lib directory of server.It should be shared by all the web applications deployed.

How to Load a Java Native/Shared Library (.so) by calling System , Copy the shared library to one of the paths already listed in java.library.path ( UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. Hi Everyone, I am currently trying to get Java to communicate with a C wrapper that communicates with Fortran libraries. I’m using aCC to create the shared library, C to compile the C functions, and f90 to compile the Fortran functions/subroutines. This is all done on the PA-RISC HPUX Version 11.11

You need to load any native code from within the server classloader and not the webapp classloader. I recommend to write a Listener which loads the binary image of the shared object into the VM. This will happens only once. Please see the AprLifecycleListener on how to properly do that. It included a JNI compnent which likely represents you case exactly.

The shared object has to reside in ${catalina.home}/lib and LD_LIBRARY_PATH hat to point to it.

Resolving java.lang.UnsatisfiedLinkError: Native Library , UnsatisfiedLinkError: Native Library already loaded . of them had to load a shared native wrapper, you are most likely to encounter this issue. in Linux system this would be file named in "java.library.path". Call System.load to load the .so from an explicitly specified absolute path. Copy the shared library to one of the paths already listed in java.library.path; Modify the LD_LIBRARY_PATH environment variable to include the directory where the shared library is located. Specify the java.library.path on the command line by using the -D option. 1.

Tomcat has a built-in solution for this issue as of versions 9.0.13, 8.5.35, and 7.0.92:

1) Use the JniLifecycleListener to load the native library.

2) Use the loadLibrary() or load() from org.apache.tomcat.jni.Library instead of System.

See more details and examples in my answer at java.lang.UnsatisfiedLinkError: Native Library already loaded in another classloader

UnsatisfiedLinkError: Using JNI to do native calls from Java, With JNI, the Java Native Interface, it is possible to call native libraries (DLLs) from Depending on your platform, this will load or payment.dll. Hello, I am using JNI to load a library which I use for a Web Service running on a Tomcat5.5-Server using Axis. My problem is that when I call a native function

Configuring the Java Native Interface (JNI) libraries, IBM WebSphere MQ provides two Java Native Interface (JNI) libraries: The mqjbnd library installed with IBM WebSphere MQ Version 7.5 can be used to connect to any IBM Linux ( zSeries platform). MQ_INSTALLATION_PATH /java/ lib UnsatisfiedLinkError: mqjbnd (Not found in java.library.path) at java.lang. I have java web application which is deployed to Tomcat. Application calls low level C library via JNI. Everything works fine when I deploy my application at first time, but as soon as I trying to

Why am I getting the Java exception 'UnsatisfiedLinkError: Native , The ODWEK shared library was loaded successfully and was used by the first ODWEK Java application. The second application� How to Fix ‘Failed to Load the JNI Shared Library’ If the issue is with your Computer or a Laptop you should try using Restoro which can scan the repositories and replace corrupt and missing files.

"Error occurred during initialization of VM", "Unable to load native , Unable to load native library: The specified procedure could not be found … UnsatisfiedLinkError: C:\Users\myuser\squish-6.x-java-xyz\bin\ squishjavawrapper.dll: Can't find dependent Squish adds several paths to the PATH environment variable to ensure that its own shared library files can be found. Calls System.load(filename). System.load() associates the loaded library with the class loader of the class that called the System method. A native library may not be loaded by more than one class loader, so calling the System method from a class that was loaded by a Webapp class loader will make it impossible for other Webapps to load it.

  • And the .class file DLLBootstrapper should be in the tomcat lib folder right?
  • Or should I pack the .class file in a jar and put in the tomcat lib foldeR?
  • yes. you should put that in tomcat lib folder. Tomcat will pick it up when it starts
  • The .class or should i export it as a jar?
  • just .class should do
  • And load it from there with System.loadLibrary? Or just leave it there and let Tomcat handle all this?
  • System.loadLibrary("libraryName");
  • Yes, i did try that. The same thing. Initially it was extracted by a ContextInitializer from a .jar file and put into tomcat/bin folder.
  • You not only have to put the library in "lib". You have to put the code that loads it there, so it gets loaded by the tomcat shared class loader and not by a webapp class loader (as you already found out you can't load it twice and another webapp is not able to access it)
  • Let's say I extract the library manually and put it in the "lib" folder. Do I have to call "System.loadLibrary" from myWebApp1 in order to use any function from that libray? Or will Tomcat load it by default on startup? Because I tried to let Tomcat load it and it doesnt work :(