2017-04-10 136 views
-1

我在ubuntu的test.cpp中创建了libcc.so,并且test.cpp的内容与ffmpeg和opencv库链接。在创建libcc.so之后,它将加载到JNItest2.java中。当我在终端运行jar文件时发生错误

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) 

有谁帮我解决这个问题呢?

感谢,林秀

+0

决定你的想法。你的源码是''cc“',但是错误信息是'test'。 – EJP

回答

0

看看这里的有关JNI的发展样本:

http://jnicookbook.owsiak.org/recipe-No-001/

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

你的情况:

  • 确保把所以如果你想使用的ffmpeg的东西,在你的代码一定要检查出这两个样品以及在LD_LIBRARY_PATH
  • 文件:

http://jnicookbook.owsiak.org/recipe-No-018/ https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo023

+0

谢谢你,我的问题是通过设置LD_LIBRARY_PATH来解决的。 – Hsiu