UnsatisfiedLinkError: no opencv_java249 in java.library.path

Meir  picture Meir · Nov 23, 2014 · Viewed 50.6k times · Source

Running into some problems making a piece of code run on my mac. Had someone write me an image analysis java app but I keep getting this error when trying to run it on netbeans.

run: Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1119) at image.prossing.Test.main(Test.java:28) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)

Have the netbeans project, and added the necessary jar files as libraries. The programmer told me to download the correct OpenCV version and copy the opencv.dll file to my java/jre/bin folder. But I cannot find the dll file or the java/jre folder. I know most programming happens on windows for a reason. Hope someone can help me resolve this issue and run this application on my mac.

Here is the first part of the code, the part that is most probably creating the error:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package image.prossing;

/**
 *
 * @author Dumith Salinda
 */
import java.util.ArrayList;
import java.util.List;
import org.opencv.core.Core;
import static org.opencv.core.Core.FONT_HERSHEY_SIMPLEX;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

public class Test {

public static void main(String[] args) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Sorry if it's not that clear, let me know what info to add if something is missing or not clear. Would truly appreciate any help you could give. Sincerely Meir Warcel

Answer

Harsh Vakharia picture Harsh Vakharia · Jan 31, 2016

Look into your OpenCV directory;

For an example this; (installed using brew install opencv3 --with-java --with-python3)

/usr/local/Cellar/opencv3/XXX/share/OpenCV/java

You will see;

libopencv_javaXXX.so    opencv-XXX.jar

Now that you already have OpenCV's native library for Java (libopencv_javaXXX.so) compiled with you, the only thing left is, mac's dynamic library.

Link libopencv_javaXXX.so to libopencv_javaXXX.dylib;

ln -s libopencv_javaXXX.so libopencv_javaXXX.dylib

Now add /usr/local/Cellar/opencv3/XXX/share/OpenCV/java as Native Library Locations in IntelliJ or something similar in Eclipse.

Or add this to your JVM arguments;

-Djava.library.path=/usr/local/Cellar/opencv3/XXX/share/OpenCV/java