1

用于视频编码的 Java 类加载包含 C++ 代码的 DLL

Unpacking debugging symbols for VideoSource.dll to \path
Checking for VideoSource.pdb...
Checking for videosource.pdb...

然后尝试从该 DLL 实例化本机 (C++) 类:

    // VideoSource() is implemented in C++ and wrapped with JNI, 
    // wrapper files were generated with SWIG 
    _videoProvider = new generated.VideoSource(); 

当 Java 类作为 JUnit 测试(提取视频数据)执行时,这种方法有效。

当我将 Java 类作为 OSGi 服务启动时,同样的事情也不起作用。

本质上,执行的是相同的代码。DLL 仍然成功加载,但上面显示的本机 (C++) 类的实例化现在引发异常:

    java.lang.UnsatisfiedLinkError: generated.VideoSourceSWIGJNI.new_VideoSource()J

当我将 Java 类作为 OSGi 服务启动而不是作为 JUnit 测试执行时,有什么不同?我该怎么做才能让它发挥作用?



背景
生成.VideoSource() 是

    public VideoSource() {
       this(VideoSourceSWIGJNI.new_VideoSource(), true);
    }

VideoSourceSWIGJNI.new_VideoSource() 是

    public final static native long new_VideoSource();

C++ 实现是

VideoSource::VideoSource() {    
   // init frame count
   m_frame_cnt = 0;
   [..]
}
4

1 回答 1

1

谢谢,普斯,给了我一点压力。在问“我是否必须尝试任何事情”之后?我很快得到了答案:

为了用我自己的话恢复来源( 1234 ):

当本机代码(例如 .so 或 .dll 库)应在 OSGi 包中使用时,必须在包的清单中声明相应的库。

清单文件可以显式编辑,如提到的源中所述,或者在使用 maven 时通过适当的插件,例如 apache felix 隐式编辑。使用的插件在 POM 文件中配置,将自动修改清单。

于 2013-04-05T14:20:25.610 回答