我写了一个使用OpenCV库的Java程序。到目前为止,我使用eclipse执行程序(并在eclipse属性中设置Jar位置)。从相对路径加载java库
这是一个大学最后的项目。我的导师现在想在他的电脑上运行这个程序。我如何生成可从特定位置(位于可执行Jar目录中的目录)加载Java OpenCV jar的可运行jar(使用Ant或使用Java代码),这将与Linux和Windows一起工作(我了解linux使用Jar文件,而Windows使用dll文件)?
我已经尝试使用:
String currentDir = System.getProperty("user.dir");
System.load(currentDir + "/path_to_jar/opencv-248.jar");
(让我们忽略了一个事实,它只会在Linux下工作),但在执行的罐子时,会出现以下错误:
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)
任何帮助将不胜感激。
Linux不加载“罐子”,它加载“所以”文件。该jar放在classpath中。共享库'.so'应该在由java命令行参数'-Djava.library.path'定义的位置中可用。 – jtahlborn 2014-08-28 13:49:18