8

I'm trying to add opencv to my Spring Boot/Maven project.

In order to use opencv library I have to provide native lib into java.library.path.

I have added following command into Eclipse VM arguments:

-Djava.library.path="D:/Projects/lib/opencv/x86/opencv_java2411.dll"

and got a following exception:

java.lang.UnsatisfiedLinkError: no opencv_java2411 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)

I'm also trying to access java.library.path directly from my code:

System.out.println(System.getProperty("java.library.path"));

and it shows provided path: D:/Projects/lib/opencv/x86/opencv_java2411.dll

What am I doing wrong ?

4 Answers 4

13

I also face the same issue doing so i did below to solve the issue.When i ran ran java -jar openCV=project jar I got the same exception as below

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.wso2telco.rnd.CamCapture.<init>(CamCapture.java:47)
at com.wso2telco.rnd.CamCapture.main(CamCapture.java:144)
... 5 more

so i did the below changes the project in the .java class i had this lines

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.loadLibrary("opencv_java320");

I removed those 2 lines and added the below line

nu.pattern.OpenCV.loadLocally();

in order add that line you need to have theses dependencies in pom.xml

<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>
<dependency>
<groupId>nu.pattern</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-4</version>
</dependency>

After doing the above modification i was able to run my program from terminal using mvn exec:java -Dexec.mainClass="com.rnd.CamCapture"

Sign up to request clarification or add additional context in comments.

Comments

6

-Djava.library.path shouldn't point to the DLL, but to the folder containing the DLL. e.g. -Djava.library.path=D:/Projects/lib/opencv/x86/

Comments

6

Just use

OpenCV.loadShared(); // tested on opencv-4.5.1-2

instead of

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

1 Comment

you saved me days of debugging! thanks.
3

On windows, set environment path which include opencv_java***.dll

e.x.
{your OpenCV path}\opencv\build\java\x64
or
{your OpenCV path}\opencv\build\java\x86

same in linux or other OS.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.