adding openCV to java buildpath in eclipse

25,198

Solution 1

I have found the solution. The tutorial skips the step, where one has to add a dll to the "native build path". The dll is located in "opencv/build/java/x86" for 32-bit java i guess. although i dont know why this is the case. Would be nice, if someone could explain that.

Solution 2

I had the same problem.

It happened because I had a mistake with the 'Native library location' configuration:

Goto Eclipse -> Window -> Preferences:

Goto Eclipse -> Window -> Preferences

Goto User Libraries:

enter image description here

Make sure that your native library location path is (change c:/opencv-2.4.9 to your own opencv folder):

C:/opencv-2.4.9/build/java/x64

and not:

C:/opencv-2.4.9/build/x64

(I missed the /java folder...)

Solution 3

The OpenCV java library is correctly linked to your Eclipse project.

The problem is the OpenCV native library which is not in the java.library.path. The exception is thrown by the line

static{ System.loadLibrary("opencv_java244"); }

which link the java library to the native one.

When you install OpenCV on your computer, it will also install a native dll library somewhere on your system, and when you call the System.loadLibrary, you tell java to search and load this library.

Your current problem is Java can not find this library in your System, either because the library is not in one of the java.library.path folders, or because you have not OpenCV installed (also take a look at the version, maybe you have not the 2.4.4 because the last is 2.4.5, in which case you will have to adapt the String).

I just noticed that your exception is about "opencv-java2.4.4". Be sure to have the right spelling of the form "opencv_java244", in your System.loadLibrary call.

I also redirect you to one of my answer, which is related to JavaCV, but that explain in more details what is going under.

Solution 4

I found a solution. The actual dll is located in the openCV\opencv\build\java\x64\ folder. In my case, its name is opencv_java247.dll, so I have changed System.loadLibrary("opencv_java244") to System.loadLibrary("opencv_java247") in my java code. I also put the native library location as E:/Sagar_tools/tools/openCV/opencv/build/java/x64 (which is my full path to the dll).

Solution 5

For me, Eclipse > external jar > native library config = opencv/build/lib worked

Share:
25,198
kiltek
Author by

kiltek

private

Updated on August 07, 2022

Comments

  • kiltek
    kiltek almost 2 years

    I have problems adding openCV to the buildpath of my eclipse-project. I have followed the instructions in the tutorial on this site: http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html#create-a-simple-java-project-in-eclipse

    But executing the code fragment gives this console output:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv-java2.4.4 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 camStatisticsTests.RawTests.main(RawTests.java:20)
    

    What do I have to do in order to get openCV working with java and eclipse. i want to use it as a normal java library.

  • kiltek
    kiltek about 11 years
    Thank you for this answer, but actually i found the problem myself. I have to give the library its dll. I dont know why, maybe you can give me more insights...
  • StreakyCobra
    StreakyCobra about 11 years
    The dll library must be in a place where java can find it. It can be either in windows $PATH, in folders listed in java.library.path, specified in Eclipse native build path (what you have done), or by passing -Djava.library.path to command line. The reason why a dll is needed for OpenCV is because OpenCV is a C++ library, and to use it from Java we need JNI. JNI maps java method calls to native library methods, which finally call the OpenCV libraries to "do the work".