2017-04-10 129 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

相關問題