从OSGi捆绑包调用本机方法时发生UnsatisfiedLinkError [英] UnsatisfiedLinkError While Calling Native Method from OSGi Bundle
问题描述
我使用eclipse File-->New-->Other-->Plug-in Project
创建了一个OSGi插件(捆绑包),称为插件1.
我想在此插件中使用本机.so
库.我在插件项目的根目录中添加了libtest_app_wrap1.so
.
I have created one OSGi plugin (Bundle) using eclipse File-->New-->Other-->Plug-in Project
called plugin 1.
I want to use a native .so
library in this plugin. I have added libtest_app_wrap1.so
at the root of my plugin project.
我的项目结构如下
这是清单文件
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类的代码
And this is the code of my Activator class
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
库.
I create jar file from plugin project using eclipse export feature. output jar file contains .so
library.
当我调用System.loadLibrary("test_app_wrap1");
时,我没有任何异常或错误,但是当我调用方法test_app.foo();
时,它却给了我UnsatisfiedLinkError
. test_app.foo()
是在.so
中定义的jni方法.
I don't get any exception or error when I call the System.loadLibrary("test_app_wrap1");
, but when I call the method test_app.foo();
it gives me UnsatisfiedLinkError
. test_app.foo()
is a jni method which is defined in .so
.
我没有任何线索可以解决此错误.请帮助解决该问题.
I am not getting any clue to resolve this error. Please help to get it resolve.
这是输出jar的内容
推荐答案
通过以下方式将jar添加到项目中:Project-> Properties-> Libraries-> Add Jar 通过plugin.xml-> Runtime-> ClassPath部分-> Add
Add the jar to the project via: Project->Properties->Libraries->Add Jar Add the jar to the class path via plugin.xml->Runtime->ClassPath section->Add
或 使用以下方法添加jar
or Use following ways to add jar
java -Djava.library.path
并按照以下步骤进行验证:
and verify by following:
System.getProperty("java.library.path")
这篇关于从OSGi捆绑包调用本机方法时发生UnsatisfiedLinkError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!