【问题标题】:OSGi API version mismatch exception issueOSGi API 版本不匹配异常问题
【发布时间】:2017-09-16 20:14:47
【问题描述】:

我正在尝试在 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,
 .

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

【问题讨论】:

  • 您确定这个问题与 OSGi 有关吗?如果您在纯 java 应用程序中从简单的 main 方法运行代码会发生什么?
  • 我试过了,效果很好……
  • 这两种情况下是否使用了相同的api依赖?
  • 我在这两种情况下都使用了相同的 JAR。这是你的意思吗?
  • 是的。不知道为什么它会产生不同的结果。也许您可以将示例的完整代码放在 github 上,以便人们可以实际尝试。

标签: java eclipse osgi osgi-bundle


【解决方案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,所以这个问题应该会消失。

【讨论】:

  • 我确定我使用的是完全相同的罐子。我最近联系了 JavaCPP 项目的维护人员,他们告诉我他们正在使用 1.9.6 版本的库来生成那些接口 jar 文件。我认为这是问题所在。在我的机器上显然我安装了 1.12.1 版本的库,这会导致异常。由于普通的 java 版本没有损坏,我得出的结论一定是 OSGi 框架对版本兼容性有一些更严格的规则......
猜你喜欢
  • 1970-01-01
  • 2011-10-13
  • 2016-07-31
  • 1970-01-01
  • 1970-01-01
  • 2011-05-08
  • 2013-01-12
  • 1970-01-01
  • 2016-10-20
相关资源
最近更新 更多