0

I have created a web application using java servlet. I am able to receive the user inputs into my servlet code but after executing some functions, I am getting this error:

java.lang.UnsatisfiedLinkError: no jniortools in java.library.path

How to resolve this?

image

Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
Prachi Katlam
  • 11
  • 1
  • 6
  • Could you please provide your code for the respective part? – Vin Apr 09 '19 at 19:04
  • Your application (servlet) uses a native library that is missing. I think it should be part of StackTrace, probably you have copy-pasted just part of that. Than set-up java.library.path to a directory containing your native libraries. – Martin Strejc Apr 09 '19 at 19:06
  • Is class `optimizer.Problem` your servlet? It is trying to load a JNI library. So your question really should be _How to load JNI library from a servlet in_ Tomcat. This question has been asked and answered several times on _Stack Overflow_. Did you see [this question](https://stackoverflow.com/questions/14018817/how-to-add-a-native-library-in-tomcat)? There is also a [HowTo](https://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat). – Abra Apr 09 '19 at 20:11
  • @Prachi Katlam did finally find a solution for this issue? – amucunguzi Aug 28 '20 at 22:30

2 Answers2

0

java.library.path is a property used by the JVM to locate native libraries. This means that the java.library.path should contains the path where you store the native libraries used by your application.

  1. Be sure that jniortools is inside the folder defined in java.library.path property.
  2. Check if you initialize java.library.path property properly. You can use -Djava.library.path=<your-path> as an argument to set it
Eymerich
  • 1
  • 1
0

I solved it with the help of this answer; and I found the minimal solution:

  • Download binaries for Java (pick it from the left menu), and select your operating system
  • Put ortools-java-.jar into your library folder in your project
  • If you use gradle as your build tool, add
    implementation fileTree(dir: 'lib', include: ['*.jar'])
    compile 'com.google.protobuf:protobuf-java:<ver>' I used '3.19.1' as <ver>
  • Extract ortools-linux-x86-64-.jar somewhere with jar -xvf ortools-linux-x86-64-<ver>.jar
  • From a resulting folder ortools-linux-x86-64 copy libjniortools.so and libortools.so.<main_ver> into a folder in your java library path, e.g. on linux into /usr/java/packages/lib.
  • Call System.loadLibrary("jniortools") once in your code, for example in a static initializer block
Tamás Sajti
  • 53
  • 1
  • 7