有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java OSGi API版本不匹配异常问题

我正在尝试在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!!");
    }

}

舱单。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,
 .

建造。属性:

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:我添加了我的版本。属性和清单文件


共 (1) 个答案

  1. # 1 楼答案

    错误是抱怨这个库:

    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版本中的代码

    很难诊断(不检查每个jar),因为您似乎没有使用正确的构建系统(您的源代码管理中有jar!)

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