2017-04-20 56 views
0

我試圖端口OSGi的Java項目。此項目取決於某些第三方JAR(librealsense JavaCPP presets)。我使用Eclipse進行開發。OSGi的API版本不匹配異常問題

我測試使用的是什麼,我需要一個子集的配置和慘敗。 我用於測試的代碼如下:

package testinglibrariesplugin; 

import org.bytedeco.javacpp.RealSense.*; 
import org.osgi.framework.BundleActivator; 
import org.osgi.framework.BundleContext; 

public class Activator implements BundleActivator { 

    public void start(BundleContext context) throws Exception { 
     System.out.println("Hello World!!"); 

     try { 
      context context1 = new context(); 
      device device = context1.get_device(0); 

      String devName = device.get_name().getString(); 

      System.out.println(devName); 
     } catch(Exception e) { 
      System.out.println(e); 
     } 
    } 

    public void stop(BundleContext context) throws Exception { 
     System.out.println("Goodbye World!!"); 
    } 

} 

的MANIFEST.MF:

... 
Bundle-ClassPath: src/bundletesting/ffmpeg-linux-x86_64.jar, 
src/bundletesting/ffmpeg-linux-x86.jar, 
src/bundletesting/ffmpeg-platform.jar, 
src/bundletesting/ffmpeg.jar, 
src/bundletesting/javacpp.jar, 
src/bundletesting/javacv.jar, 
src/bundletesting/librealsense-linux-x86_64.jar, 
src/bundletesting/librealsense-linux-x86.jar, 
src/bundletesting/librealsense-platform.jar, 
src/bundletesting/librealsense.jar, 
src/bundletesting/opencv-linux-x86_64.jar, 
src/bundletesting/opencv-linux-x86.jar, 
src/bundletesting/opencv-platform.jar, 
src/bundletesting/opencv.jar, 
. 

build.properties:

source.. = src/ 
output.. = bin/ 
bin.includes = META-INF/,\ 
       .,\ 
       src/bundletesting/ffmpeg-linux-x86_64.jar,\ 
       src/bundletesting/ffmpeg-linux-x86.jar,\ 
       src/bundletesting/ffmpeg-platform.jar,\ 
       src/bundletesting/ffmpeg.jar,\ 
       src/bundletesting/javacpp.jar,\ 
       src/bundletesting/javacv.jar,\ 
       src/bundletesting/librealsense-linux-x86_64.jar,\ 
       src/bundletesting/librealsense-linux-x86.jar,\ 
       src/bundletesting/librealsense-platform.jar,\ 
       src/bundletesting/librealsense.jar,\ 
       src/bundletesting/opencv-linux-x86_64.jar,\ 
       src/bundletesting/opencv-linux-x86.jar,\ 
       src/bundletesting/opencv-platform.jar,\ 
       src/bundletesting/opencv.jar 

的jar文件我用的是可下載from my Github repo

我得到以下錯誤:

Hello World!! 
java.lang.RuntimeException: API version mismatch: librealsense.so was compiled with API version 1.12.1 but the application was compiled with 1.9.6! Make sure correct version of the library is installed (make install) 

由於代碼的工作只使用Java的我必須假設有在Eclipse/OSGi的配置問題。我想忽略這個API不匹配,但我在這個環境中並不是很有經驗,我不知道如何繼續。如果這不是解決問題的正確方法,請告訴我。

任何幫助表示讚賞。

編輯:這是我在一個普通的Java應用程序中使用的代碼和工作原理:

import org.bytedeco.javacpp.RealSense.*; 

public class Main { 

    public static void main(String[] args) { 

     context context = new context(); 
     device device = context.get_device(0); 

     String devName = device.get_name().getString(); 

     System.out.println(devName); 

    } 

} 

輸出:Intel RealSense SR300預期。

編輯2:我將我的build.properties和清單文件

+0

你確定這個問題是OSGi相關?如果您在簡單的Java應用程序中使用簡單的主要方法運行代碼,會發生什麼情況? –

+0

我試着和它完美的作品... – mattdibi

+0

你在這兩種情況下使用相同的API的依賴? –

回答

0

錯誤是抱怨這個LIB:

librealsense.so was compiled with API version 1.12.1 but the application was compiled with 1.9.6! 

它似乎並沒有成爲Java,除非他們只是忘了刪除.so從名字?

反正錯誤中提到您的應用程序是對錯誤的版本編譯的,所以這不是一個運行時錯誤的OSGi(特別是考慮到要嵌入的罐子到您的應用程序包)。這是你的類的字節碼,這似乎是從1.9.6版本的庫,指的代碼時,也就是在運行時出現的版本是1.12.1。

因爲您似乎沒有使用正確的構建系統(您的源代碼管理器中有罐子),所以很難診斷(沒有檢查每個罐子)。

我建議你確認你的編譯步驟包含與你在運行時給OSGi完全相同的jar,所以這個問題應該消失。

+0

我相信我使用完全相同的罐子。我最近聯繫了JavaCPP項目的mantainers,他們告訴我他們正在使用庫的1.9.6版本來生成這些接口jar文件。我認爲這是問題。在我的機器上顯然我安裝了1.12.1版本的庫,這導致了異常。由於普通的java版本沒有中斷,我得出結論,它必須是OSGi框架,它有一些關於版本兼容性的更嚴格的規則。 – mattdibi