从OSGi Bundle

时间:2017-09-15 09:29:35

标签: java eclipse-plugin osgi shared-libraries swig

我使用名为plugin 1的eclipse File-->New-->Other-->Plug-in Project创建了一个OSGi插件(Bundle)。 我想在此插件中使用本机.so库。我在插件项目的根目录添加了libtest_app_wrap1.so

我的项目结构如下所示

plugin project structure

这是清单文件

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JniTest
Bundle-SymbolicName: JniTest
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: jnitest.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-NativeCode: libtest_app_wrap1.so; osname=linux; processor=amd64

这是我的Activator类的代码

    package jnitest;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

    public Activator() {
        System.loadLibrary("test_app_wrap1");
        System.out.println("Library Loaded Successfully.......");
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
    public void start(BundleContext context) throws Exception {
        try {
            test_app.foo();

        } catch (Throwable tr) {
            tr.printStackTrace();

        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    public void stop(BundleContext context) throws Exception {
        System.out.println("Goodbye World!!");
    }

}

我使用eclipse导出功能从插件项目创建jar文件。输出jar文件包含.so库。

当我致电System.loadLibrary("test_app_wrap1");时,我没有收到任何异常或错误,但是当我调用方法test_app.foo();时,它会给我UnsatisfiedLinkErrortest_app.foo()是一种jni方法,在.so中定义。

我没有得到解决此错误的任何线索。请帮助解决问题。

[编辑:输出捆绑内容]

以下是输出jar的内容

jar output

1 个答案:

答案 0 :(得分:-1)

通过以下方式将jar添加到项目中:Project-> Properties-> Libraries-> Add Jar 通过plugin.xml-> Runtime-> ClassPath section-> Add

将jar添加到类路径

或 使用以下方法添加jar

innerText

并通过以下方式验证:

java -Djava.library.path