0

I've written a Java program that uses OpenCV library. So far, I executed the program with eclipse (and set the Jar location in eclipse properties).

This is a college final project. My instructor now wants to run the program in his computer. How can I generate a runnable jar(using Ant or using Java code) that will load the Java OpenCV jar from specific location (a directory that will be located in the executable Jar directory), that will work with Linux and Windows (I understood that linux uses a Jar file, and Windows uses a dll file)?

I've tried using:

String currentDir = System.getProperty("user.dir");
System.load(currentDir + "/path_to_jar/opencv-248.jar");

(let's ignore the fact that it will only work with linux) But when executing the jar, the following error occurs:

OpenJDK 64-Bit Server VM warning: You have loaded library /path_to_jar/opencv-248.jar which might have disabled stack guard. The VM will try to fix the stack guard now. It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'. Exception in thread "main" java.lang.UnsatisfiedLinkError: /path_to_jar/opencv-248.jar: /path_to_jar/opencv-248.jar: invalid ELF header (Possible cause: endianness mismatch)

Any help would be highly appreciated.

user130955
  • 75
  • 10
  • 1
    linux does not load "jars", it loads '.so' files. the jar goes on the classpath. the shared library '.so' should be available in a location defined by the java command line argument '-Djava.library.path'. – jtahlborn Aug 28 '14 at 13:49

1 Answers1

1

Use the classpath option for your java executable.

If you're running OpenJDK read the manpage at http://linux.die.net/man/1/java-java-1.6.0-openjdk

You should be able to use something along the lines of: java -jar yourapp.jar -cp ./path_to_jar/

Another option is to build a JAR which includes its own dependencies. Here are some examples I found using the search terms "java create jar include dependencies":

Using Maven

Using Eclipse

Community
  • 1
  • 1
Freiheit
  • 8,408
  • 6
  • 59
  • 101
  • Both options output the error: "java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path". Couldn't it be done without the user having to change his system? – user130955 Aug 28 '14 at 15:46
  • The links I provided should explain how to build a JAR which includes its dependencies. Can you update your original question with the alternatives you tried and any errors produced? – Freiheit Aug 28 '14 at 15:49