Executing Java(Eclipse) OpenCV code from JAR

asked 2017-03-21 14:20:46 -0500

Vikram Gupta gravatar image

updated 2017-03-21 18:05:37 -0500

Hi All,

I'm just getting started with Java(Eclipse) and OpenCV . The "Using OpenCV Java with Eclipse" tutorial was excellent, and I'm able to excute the code in Eclipse with "Debug" or "Run".

However , eventually I will need to export the code as a JAR (its going to be a plugin for MicroManager and ImageJ).

When I try to export the project as "Runnable JAR file" , when I try to run it with java -jar myjar.jar

I get the following error

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java2411 in java.library.pa
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at cv_sandbox.hello_world.main(hello_world.java:22)
        ... 5 more

When I was exporting , I set the Library handling to both "Extract required lib into generated JAR" and "Package required lib into generated JAR" , I get similar errors.

The code I'm running is the one from the tutorial.

    public static void main(String[] args){

        Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
        System.out.println("mat = " + mat.dump());

And it runs fine when I use the Eclipse Debug or Run button.

Any help would be appreciated. Thanks.

EDIT1: Incase its helpful. I'm on windows 7 pc EDIT2: Found this thread(error-when-lunching-the-runnable-jar-file) , and coping the opencv_java2411.dll seems to fix the issue. Not totally satisfied with that fix. How can I get my code to pickup the dll for a specified location.

edit retag flag offensive close merge delete