Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.UnsatisfiedLinkError: no opencv_java2411 in java.library.path

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 ?

like image 995
alexanoid Avatar asked Dec 19 '22 15:12

alexanoid


1 Answers

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"

like image 98
Sheshan Gamage Avatar answered Jan 18 '23 22:01

Sheshan Gamage