1

This question might have been asked earlier on SO, and please be assured I did check all the available solutions. Was still unable to get it to run

My problem is exactly as described in this post Shared native library in Tomcat UnsatisfiedLinkError

Standalone Java application is running perfectly well. However with Tomcat(9) it fails to run and throws

java.lang.UnsatisfiedLinkError: third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init()V
    at third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init(Native Method)
    at third_party.org.chokkan.crfsuite.crfsuiteJNI.<clinit>(crfsuiteJNI.java:87)
    at third_party.org.chokkan.crfsuite.Tagger.<init>(Tagger.java:39)

I know that my DLL is being loaded, also I checked that the folder my dll is in, is in the PATH variable. I have also checked the classes being loaded and the DLL is infact being loaded.

I have noticed 3 types of UnsatisfiedLinkError at SO

1) java.lang.UnsatisfiedLinkError: third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init()V 2) java.lang.UnsatisfiedLinkError: third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init()B 3) Where the class loader is loading twice.

I believe the V , at the end does signifies something. But I am not able to figure out exactly what?

One of the accepted answers in the SO post I shared above claims it has something to do with version. I do not understand how is that an acceptable solution since it works perfectly well when run as a standalone java application.

Wasted a lot of time already, any help is appreciable.

Thanks Chahat

Community
  • 1
  • 1
user4772933
  • 311
  • 3
  • 13
  • `B` (Byte) and `V` (Void) belong to the signature of the `swing_module_init()V` method(s) and only tell that the return type is `Void` (or `Byte` in the other case), please see: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html – nyyrikki Sep 28 '16 at 13:21
  • thanks nyyrikki for the answer, Could you please tell me how to fix it though? to make the native functions call work within web application (tomcat) ?? Thanks – user4772933 Oct 05 '16 at 12:12
  • Does it work for you when not running in Tomcat (not only loading, but calling native methods)? If I understand your description from above correctly you are more referring to the linked problem on stackoverflow. It would also help if you show us the header file generated with javah. – nyyrikki Oct 05 '16 at 12:49
  • Yes it works when I run it as a Standard Java Application but not with Tomcat. Am using a 3rd party code in my application. it is available here on GitHub https://github.com/vinhkhuc/jcrfsuite He is using SWIG (am not familiar with SWIG, I just use his code as it is and it works in a Standalone App) Here is the header file https://github.com/vinhkhuc/jcrfsuite/blob/master/src/main/java/third_party/org/chokkan/crfsuite/hpp/crfsuite.hpp And this is the place where the tomcat application fails /third_party/org/chokkan/crfsuite/crfsuiteJNI.java (Line Number 85) – user4772933 Oct 05 '16 at 13:15

2 Answers2

0

I faced with the same issue. I finally find the solution. It works for me.

First, I instaled libLBFGS and crfsuite. You can find the instruction here (http://www.chokkan.org/software/crfsuite/manual.html). The libcrfsuite.so will be install in /usr/local/lib

Second, I edit tomcat config in order to load native library. I create setenv.sh in tomcat bin folder, set CATALINA_OPTS variable with content :

export CATALINA_OPTS="-Djava.library.path=/usr/local/bin:/usr/local/lib"

Finally, I used custom ServletContextListener and explicitly load libcrfsuite.so by System.load(). I go this link to download lib (https://github.com/vinhkhuc/jcrfsuite/tree/master/src/main/resources/crfsuite-0.12)

0

I had a similar problem but not with Tomcat. I ended up copying the logic from one of their classes and simply invoking:

static {
    try {
        CrfSuiteLoader.load();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Ohad Zadok
  • 3,452
  • 1
  • 22
  • 26