0

I want to use OpenCV code in maven project, the opencv-310.jar created and run well.

following this page the way call local jar file, I install the jar

mvn install:install-file 
-Dfile=/home/administrator/NetBeansProjects/OpenCV_Maven/opencv-310.jar 
-DgroupId=localLibrary 
-DartifactId=OpenCV -Dversion=3.1.0 -Dpackaging=jar 
-DgeneratePom=true

and make POM as below code

<dependencies>
    <dependency>
        <groupId>localLibrary</groupId>
        <artifactId>OpenCV</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>    

Then run the Face detection application sample code. The exception, like below, occurred at the line calling Core.NATIVE_LIBRARY_NAME, seems it failed to found jar.

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

I can't figure out how to fix, the same problem appeared when I practice the library with destop application, but can't solve it in same way.(add VM option-Djava.library.path)

By the way, I don't use libopencv_java310.so that was created with opencv-310.jar at the same time. I am not sure is it necessary or not, if it have to be add to maven project, please tell me how to use it, I never used this kind of file.

Thanks for helps.

Community
  • 1
  • 1
TomN
  • 574
  • 3
  • 18
  • 1
    " I am not sure is it necessary or not". Well the runtime error you get seems to indicate it is. That Java library might just be an entry point to native code call (via JNI), hence the need to add the native library in the `java.library.path`. – Tome Feb 18 '16 at 08:38

1 Answers1

0

As @Tome said, the problem cause by native library missed.

So I do like,

public static void main(String[] args) {
System.out.println("Hello, OpenCV");

// Load the native library.
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME); instead by below code
String path = "/home/administrator/OpenCV_jar/libopencv_java310.so";
System.load(path);
new DetectFaceDemo().run();
}
TomN
  • 574
  • 3
  • 18