OSGi API版本不匹配异常问题

时间:2017-04-20 09:21:43

标签: java eclipse osgi osgi-bundle

我试图在OSGi中移植Java项目。该项目依赖于某些第三方JAR(librealsense JavaCPP presets)。我正在使用Eclipse进行开发。

我已经使用我需要的一部分测试了配置,并且失败了。 我用于测试的代码如下:

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和清单文件

1 个答案:

答案 0 :(得分:0)

错误是抱怨这个lib:

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

它似乎不是Java,除非他们忘记从名称中删除.so

无论如何,错误提到您的应用程序是针对错误版本编译的,因此这不是运行时OSGi错误(特别是考虑到您将jar嵌入到应用程序包中)。这是你的班级'当运行时出现的版本是1.12.1时,字节码似乎是指代1.9.6版本库中的代码。

很难诊断(没有检查你已经得到的每个罐子),因为你似乎没有使用正确的构建系统(你的源代码控制器中有罐子!)。 / p>

我建议您验证您的编译步骤是否包含与您在运行时提供给OSGi的完全相同的jar,因此这个问题应该消失。

相关问题