[英]UnsatisfiedLinkError While Calling Native Method from OSGi Bundle
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. 我使用eclipse File-->New-->Other-->Plug-in Project
创建了一个OSGi插件(捆绑包),该插件称为插件1。我想在此插件中使用本机.so
库。 I have added libtest_app_wrap1.so
at the root of my plugin project. 我在插件项目的根目录下添加了libtest_app_wrap1.so
。
my project structure looks like below 我的项目结构如下
And here is the manifest file 这是清单文件
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
And this is the code of my Activator class 这是我的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!!");
}
}
I create jar file from plugin project using eclipse export feature. 我使用eclipse导出功能从插件项目创建jar文件。 output jar file contains .so
library. 输出jar文件包含.so
库。
I don't get any exception or error when I call the System.loadLibrary("test_app_wrap1");
当我调用System.loadLibrary("test_app_wrap1");
时,我没有任何异常或错误System.loadLibrary("test_app_wrap1");
, but when I call the method test_app.foo();
,但是当我调用方法test_app.foo();
it gives me UnsatisfiedLinkError
. 它给了我UnsatisfiedLinkError
。 test_app.foo()
is a jni method which is defined in .so
. test_app.foo()
是在.so
定义的jni方法。
I am not getting any clue to resolve this error. 我没有任何线索可以解决此错误。 Please help to get it resolve. 请帮助使其解决。
[Edit: Output bundle content] [编辑:输出捆绑包内容]
Here is the content of the output jar 这是输出jar的内容
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添加到项目中:Project-> Properties-> Libraries-> Add Jar通过plugin.xml-> Runtime-> ClassPath部分-> Add将jar添加到类路径。
or Use following ways to add jar 或使用以下方式添加罐子
java -Djava.library.path
and verify by following: 并按照以下步骤进行验证:
System.getProperty("java.library.path")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.