Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 this, 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