Exporting Executable jar file that uses opencv
Asked Answered
P

1

3

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)
Piperidine answered 29/4, 2013 at 15:53 Comment(0)
F
5

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.

Floyfloyd answered 30/4, 2013 at 20:56 Comment(2)
in my System , OpenCV is installed. Once I try to run the project from eclipse , everything works fine . but when I try to do the same from runnabelJar it doesn't. The problem I found it that I didn't include .dll files , so how should I do it.Kwh
Facing same problem. Please helpArrogate

© 2022 - 2024 — McMap. All rights reserved.