How to create jar file with OpenCV in Eclipse?

Create a jar file including an external library (OpenCV) in eclipse

  • I'm trying to create an executable jar of my application on a Mac, which uses functions from OpenCV. However when I try to create the jar in eclipse I get this error: Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at imageRegistration.ImageGUI.main(ImageGUI.java:643) The error I think is because the there is a .dylib file that is linked to the OpenCV jar and is not being packaged with it. I have found http://stackoverflow.com/questions/18269570/how-to-package-opencv-java-in-a-jar, which seems to be the same issue I am having, but the solution doesn't work for me. This is what I have done: public static void libLoad(){ try{ InputStream in = ImageGUI.class.getResourceAsStream("/lib/opencv-2.4.8 MAC/build/lib/libopencv_java248.dylib"); File fileOut = File.createTempFile("lib", ".dylib"); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); System.load(fileOut.toString()); } catch(Exception e) { System.out.println("Failed to load opencv native library \n" + e); } } The error I get when I run this is: Failed to load opencv native library java.lang.NullPointerException EDIT: Here is the full stack trace: java.lang.NullPointerException at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1792) at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769) at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744) at imageRegistration.ImageGUI.libLoad(ImageGUI.java:624) at imageRegistration.ImageGUI.main(ImageGUI.java:643)

  • Answer:

    You need to print full stack trace, it's not clear from where NPE is coming. Most probably ImageGUI.class.getResourceAsStream returns null. If this is true it is eihter because path is wrong or lib is not in the jar

user2916314 at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.