1

I've been trying to execute a jar file through command line but I'm still getting an exception that I'm missing a library even though it was properly added as it's shown here. The library that I'm trying to run my code with is the opencv's lib. I'm able to run my app from intellij and generate a jar artifact that I can see the jar grows in size when I add the opencv lib but when I try to run the app from the command line with "java -jar Test.jar" I get the message that I'm missing the opencv library.

rinaldi@rinaldi-work:~/Projects/Test/out/artifacts/Test_jar$ java -jar Test.jar Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 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 HelloWorld.<clinit>(HelloWorld.java:14)
at Main.main(Main.java:4)

I've also tried to run the app adding the path to the opencv's library:

:~/Projects/Test/out/production/Test$ java -cp .:~/Sources/opencv-master/build/bin/opencv-310.jar Main

And another attempt because opencv needs not only it's jar but also the /opencv-master/build/lib/ directory:

:~/Projects/Test/src$ java -cp :/home/rinaldi/Sources/opencv-master/build/bin/opencv-310.jar:/home/rinaldi/Sources/opencv-master/build/lib/ Main

Below are the images from intellij's configuration.

Artifacts window

Modules window

Community
  • 1
  • 1
Rinaldi Segecin
  • 449
  • 8
  • 23

1 Answers1

0

I had to add the library this way:

java -jar -Djava.library.path=/home/rinaldi/Sources/opencv-master/build/lib test.jar

Hope this helps someone.

Rinaldi Segecin
  • 449
  • 8
  • 23