Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting Executable jar file that uses opencv

While exporting in eclipse I choose "Package required libraries into generated jar". The jar file works only in my machine. However, when I test it on other machine it gives this Exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:489)
at com.googlecode.javacpp.Loader.load(Loader.java:431)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
at mains.<clinit>(mains.java:25)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
like image 433
Hossam Alaa Avatar asked Jan 18 '26 05:01

Hossam Alaa


1 Answers

Short answer

You must install OpenCV (as mentioned in JavaCV requirements) and JavaCV on the system in order to use JavaCV. As you probably installed them for development on your computer the application work, but the other machine probably has not them installed and thus the jar does'nt work.

Long answer

The problem is not the JavaCV library, which appears to be correctly included into your jar as shown by the lines:

at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:489)
at com.googlecode.javacpp.Loader.load(Loader.java:431)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)

The fact is JavaCV is build on top of OpenCV. OpenCV being a C++ library, the only way to use it from Java is to use JNI calls.

JNI require two components:

  • A java library (usually with extension *.jar) containing java method that calls native library
  • A native library (usually with extension *.so for linux or *.dll for windows) that "do the work", in this case that "use OpenCV library"

The first one is provided by JavaCV and included into your jar application. The second one is system dependent (Os, architecture, ...) and must be into the java library path.

This is the actual error: it can not find libjniopencv_core.so into java.library.path. The jniopencv_core library is provided by JavaCV too but is installed somewhere on the system (/usr/lib/ for instance) and thus not included into the final jar.

Even if you find a way to include it into the final application, this library will need to use OpenCV libraries which are not installed on the system too. To summarize the needs:

  1. JavaCV java library, that will call (with JNI):
  2. JavaCV native library, that will use:
  3. OpenCV libraries, that will really do the work.

Without one of this point the application will not work. Thus OpenCV and JavaCV must be installed into the system.

like image 90
StreakyCobra Avatar answered Jan 19 '26 20:01

StreakyCobra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!