0

I'm writing a java application (on Linux OS) which accesses the webcam and display a video on a JPanel. I'm using openCV libraries in order to obtain it (also because I would like to add some image processing code). I followed this guide to compile the openCV library for Java

and the only way I could make it work was by creating an user library linked to the folder where I have the corresponding jar file. (I tried to directly import the jar file but I have some runtime exception, so I gave up).

This is my situation. Now I have a working application (if I execute it from within Eclipse), and I want to export it as a single jar (or something executable outside Eclipse). I tried to achieve this by selecting these options.

The problem is that now I want test if the jar works by executing the following command from terminal (where Untitled.jar is the name of the exported code):

java -jar Untitled.jar 

but I receive this error (I bolded the main problem):

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_java331 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 myRefreshTest.Main.main(Main.java:8)

opencv_java331 is the name of the .so library generated after building openCV for Java (opencv_java331.so)

I tried several way to export my program, also by selecting the 3rd option in the Eclipse export popup ("Copy required libraries into sub-folder next to the generated JAR) and then executing

java -cp Untitled_lib/opencv-331.jar  -jar Untitled.jar 

but terminal returns this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java331 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 myRefreshTest.Main.main(Main.java:8)

So, the problem is clear, it can't find the openCV .so library. I tried to use also option -Djava.library.path but it is not working (or at least I'm not using it properly) I'm not a Java expert and I cannot understand how to fix this problem. Does anyone know how to fix this issue?

roiko
  • 33
  • 6
  • I successfully made it working by following these steps: 1) Export the project as "Runnable JAR library" by selecting the option "Package required libraries into generated JAR" 2) Create a new folder and paste inside the .so library (libopencv_java331.so) 3) Execute the jar with the command `java -Djava.library.path=./native/lib/ -jar Untitled.jar` The solution works, but I would like to know if there is a way to make the jar execute without this workaround... – roiko Dec 04 '17 at 18:27
  • Possible duplicate of [How to create a jar with external libraries included in Eclipse?](https://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse) – tkotisis Dec 05 '17 at 08:41

0 Answers0