我在ubuntu的test.cpp中创建了libcc.so,test.cpp的内容与ffmpeg和opencv库链接。在创建libcc.so之后,它被加载到JNItest2.java中。
JNItest2.java:
public class JNItest2 {
public native void helloworld();
static{
String libPath= "/home/sun/workspace/JNItest2/src";
System.setProperty("java.library.path",libPath);
String Path = System.getProperty("java.library.path");
System.out.println("java.library.path=" + Path);
System.loadLibrary("cc");
}
public static void main(String[] args){
new JNItest2().helloworld();
}
}
但是,JNItest2.java可以在Eclipse上运行,导出的jar文件无法在终端中运行。
终端中的错误消息:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no test in
java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at
java.lang.Runtime.loadLibrary0(Runtime.java:870) at
java.lang.System.loadLibrary(System.java:1122) at JNItest2.<clinit>
(JNItest2.java:23)
有没有人帮我解决这个问题?
谢谢,Hsiu
答案 0 :(得分:0)
在这里查看与JNI开发相关的示例:
http://jnicookbook.owsiak.org/recipe-No-001/
这是一个非常简单的应用程序,您可以在其中查看运行基于JNI的代码所需的所有元素。
在你的情况下:
http://jnicookbook.owsiak.org/recipe-No-018/ https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo023