2017-04-20 57 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