【发布时间】: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