Native library in Tomcat UnsatisfiedLinkError + Windows + eclipse

混江龙づ霸主 提交于 2020-01-05 06:27:09

问题


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


回答1:


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)




回答2:


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);
    }
}


来源:https://stackoverflow.com/questions/39741971/native-library-in-tomcat-unsatisfiedlinkerror-windows-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!