Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在终端中运行jar文件时出错_Java_Jar_Java Native Interface - Fatal编程技术网

Java 在终端中运行jar文件时出错

Java 在终端中运行jar文件时出错,java,jar,java-native-interface,Java,Jar,Java Native Interface,我从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"; Syste

我从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)
线程“main”java.lang.UnsatisfiedLinkError中出现异常:中没有测试
java.library.path位于
loadLibrary(ClassLoader.java:1867)位于
位于的java.lang.Runtime.loadLibrary0(Runtime.java:870)
JNItest2上的java.lang.System.loadLibrary(System.java:1122)。
(JNItest2.java:23)
有人帮我解决这个问题吗


谢谢,Xiu

在这里查看与JNI开发相关的示例:

这是一个非常简单的应用程序,您可以查看运行基于JNI的代码所需的所有元素

就你而言:

  • 确保将so文件放在LD_LIBRARY_路径中
  • 如果您想在代码中使用ffmpeg内容,请确保同时查看以下两个示例:

下定决心吧。您的源代码显示为
“cc”
,但错误消息显示为
test
。谢谢您,我的问题通过设置LD\u LIBRARY\u PATH解决了。