Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path

I'm currently trying to set up OpenCV on my 32-bit laptop, but I keep getting an error message which is confusing me:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at hello.main(hello.java:8)

I've tried switching a few things around, like going into User Libraries and changing the Native Library Location to \x64 instead of \x86, but that hasn't worked. I've also made sure that my Java project has OpenCV-2.4.9 as one of its libraries, which it has. I've also tried 'cleaning' all projects, but that hasn't worked (does it ever?). So I've followed all the instructions in the set-up tutorial but it still isn't working.

Does anyone know what the problem might be here? Thanks in advance...

like image 601
Zetland Avatar asked Dec 12 '22 00:12

Zetland


2 Answers

The problem is that the native opencv library cannot be found because it is not in the java.library.path (it is a native library and it should not be in usual java classpath, but it must be in the java.library.path).

Your opencv distribution should contains:

  • a java library : opencv249.jar. This library is mainly a java to native library with jni stuff allowing you to do native calls from java code. It must be in the classpath (and according the error you have and your explanations : it is on your classpath --> everything is ok here)

  • a native library named libopencv_java249.so and this must be in your java.library.path . Obviously : it is not : the UnsatisfiedLinkError is the symptom of a missing native library. To include this native library: start your java program with the following parameter:

    -Djava.library.path=/path/to/the/directory/of/ibopencv_java249.so

like image 155
ben75 Avatar answered Dec 28 '22 08:12

ben75


Another possible solution which worked for me on Ubuntu: Instead of setting the JVM parameter to the exact libopen.so file, try setting it to the folder:

-Djava.library.path=/opencv-3.2.0/opencv/build/lib/
like image 24
Ognjen Mišić Avatar answered Dec 28 '22 06:12

Ognjen Mišić