Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
569 views
in Technique[技术] by (71.8m points)

eclipse - 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...