Ask Your Question
2

JNI error on playframework v2.1.1 UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J

asked 2013-07-15 00:41:00 -0600

Yoonje Choi gravatar image

Hi, I'm trying to run HelloCV example on playframework through JNI. java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J occured.

I read an issue about gcc visibility option. http://code.opencv.org/issues/3077#note-3

Though I tried using opencv-249 which has fixed a visibility issue, the same error occurs.

If I use openCV not on playframework, UnsatisfiedLinkError doesn't occur. working well. Only when I run HelloCV on playframework, UnsatisfiedLinkError occurs..

Does anybody have a clue?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
3

answered 2013-07-19 04:30:05 -0600

Yoonje Choi gravatar image

updated 2013-07-19 04:31:38 -0600

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.

edit flag offensive delete link more

Comments

Any ideas why you cannot do it with System.loadLibrary(Core.NATIVE_LIBRARY_NAME) ?

zikolach gravatar imagezikolach ( 2014-10-05 08:15:55 -0600 )edit
2

answered 2013-07-18 08:15:19 -0600

Yoonje Choi gravatar image

updated 2013-07-19 04:13:32 -0600

I solved the problem.

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".

According to apple's doc on https://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html "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.!!

[UPDATE] This solution is only for Glassfish v3. It doesn't works for Play framework. I Just wrote after experimenting on glassfish. I'm so sorry confuse you. But I found a way for Play framework too and going to write about it right now~

edit flag offensive delete link more

Comments

I've been having a similar problem lately - how did you get Play to find the appropriate native libraries? Did you update the configuration in Build.scala in some way? Updating the extension doesn't seem to be enough in my case.

Charles_Lovely gravatar imageCharles_Lovely ( 2013-07-18 14:45:44 -0600 )edit

I wrote an answer below. Check it out.

Yoonje Choi gravatar imageYoonje Choi ( 2013-07-19 04:31:06 -0600 )edit
0

answered 2016-06-28 22:10:26 -0600

you don't check system library when add opencv.jar in eclipse image description

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-15 00:41:00 -0600

Seen: 9,193 times

Last updated: Jun 28 '16