how to load native library? UnsatisfiedLinkError

3,404 views
Skip to first unread message

Yoonje Choi

unread,
Jul 15, 2013, 2:13:38 AM7/15/13
to play-fr...@googlegroups.com
Hi, I'm try to use opencv on playframwork 2.1.1 ( mountain lion 10.8.4)

app/target/native_libraries/64bits/libopencv_java246.dylib
app/lib/opencv-246.jar

I created public class Global extends GlobalSettings class to load native library with System.loadLibrary("opencv_java246").

Although onStart() or beforeStart() looks like loading the library I specified, UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J occurs in controller method.

java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J

The other test JNI library, libHelloJNI.dylib which I made works well on playframework with the same procedure..

What's wrong with opencv lib or app classloader? ..


Yoonje Choi

unread,
Jul 18, 2013, 9:16:23 AM7/18/13
to play-fr...@googlegroups.com
I solved the problem myself. 

For those who use osx version other than v10.5 and Apple's JDK (maybe jdk 6), not oracle's jdk.

If you get UnsatisfiedLinkError with JNI, CHANGE your native library file extension to ".jnilib".
Though java.library.path property is set properly, JVM may not load native library if file extension is not ".jnilib" such as ".dylib".

"JNI libraries are named with the library name used in the System.loadLibrary() method of your Java code, prefixed by lib and suffixed with .jnilib. For example, System.loadLibrary("hello") loads the library named libhello.jnilib. Java HotSpot also recognizes .dylib as a valid JNI library format as of Mac OS X v10.5."

Maybe on v10.5, ".dylib" works. But in my case on v10.8.4, mountain lion, ".dylib" doesn't work.

If you get problem during java development on mac, FIND documentation on developer.apple.com as well as oracle's doc. Don't forget that you may use Apple's JDK.!!

2013년 7월 15일 월요일 오후 3시 13분 38초 UTC+9, Yoonje Choi 님의 말:

Yoonje Choi

unread,
Jul 19, 2013, 5:37:01 AM7/19/13
to play-fr...@googlegroups.com
This doesn't work for Play framework. Just for Glassfish v3. 


2013년 7월 18일 목요일 오후 10시 16분 23초 UTC+9, Yoonje Choi 님의 말:

Yoonje Choi

unread,
Jul 19, 2013, 5:40:14 AM7/19/13
to play-fr...@googlegroups.com
When you want to use OpenCV or any other native libraries on Playframework, You MUST run your application with "play start" command, not "play run".

"play run" command starts your application in development mode and "play start" command starts in production mode. I don't know every difference between them but one obvious thing is ,

Only when we use "play start", a new JVM for you application is launched and it loads native libraries you specified by System.load("/absolute/path/to/your/so/or/jnilib/inOSX/not/dylib/filename.jnilib");

How to load native lib is following.

Create Global.java which has empty package name. (refer this link )

public class Global extends GlobalSettings {

@Override
public void beforeStart(Application app) {
    // TODO Auto-generated method stub
    super.beforeStart(app);


    String libopencv_java = "/Users/yoonjechoi/git/myFirstApp/target/native_libraries/64bits/libopencv_java246.jnilib";
    System.load(libopencv_java);
}
}


then you can use classes of OpenCV in your Play application's controllers.

System.loadLibrary("opencv_java246") doesn't works. I don't know why. I don't have time to dig why. -_-;

Please give hints if you know why.

2013년 7월 15일 월요일 오후 3시 13분 38초 UTC+9, Yoonje Choi 님의 말:
Hi, I'm try to use opencv on playframwork 2.1.1 ( mountain lion 10.8.4)

lnx...@gmail.com

unread,
Jan 16, 2014, 1:04:49 AM1/16/14
to play-fr...@googlegroups.com
I haven't found a solution to a problem, else than running play start, and running it as play start while development sucks, so I've created an issue: https://github.com/playframework/playframework/issues/2212 . If you encounter the problem, you can add there a comment, describing the situation.
Adding there a comment rases it upper in issue list. Upper the issue is, higher the probability, that it'll be fixed.

пятница, 19 июля 2013 г., 13:40:14 UTC+4 пользователь Yoonje Choi написал:
Reply all
Reply to author
Forward
0 new messages