使用带有osgi的.so库使用JNA

时间:2014-02-10 15:41:13

标签: nullpointerexception osgi jna native-code osgi-bundle

我正在尝试创建一个OSGi包,它使用linux上的共享库来打印“Hello world”

这是Bundle的manifest.mf

Manifest-Version: 2.0
Bundle-Name: HelloWorld
Bundle-SymbolicName: HelloWorld
Bundle-Version: 1.0.0
Bundle-Description: Hello world bundle
Bundle-Vendor: Knopflerfish
Bundle-Activator: impl.HelloActivator
Bundle-Category: example
Eclipse-PlatformFilter: (& (osgi.os=linux) (osgi.arch=arm))
Bundle-ClassPath: libs/, .
Bundle-NativeCode: libs/libtest.so; osname=Linux; processor=x86
Import-Package: org.osgi.framework, com.sun.jna

test.c的

#include <stdio.h>


void printhello()
{
    printf("hello world from c");
}

HelloActivator.java

package impl;

import jna.printhello;

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





public class HelloActivator implements BundleActivator {

    public static BundleContext bc=null;


    public void start(BundleContext arg0) throws Exception {

    HelloActivator.bc=arg0;
    printhello demo = (printhello) Native.loadLibrary("test",printhello.class);
    demo.printhello();




}


public void stop(BundleContext arg0) throws Exception {

    HelloActivator.bc=null;
}

}

和printhello.java

package jna;

import com.sun.jna.Library;

public interface printhello extends Library {

public void printhello ();

}

在knopflerfish框架中安装Bundle之后我收到了这个错误:

java.lang.NullPointerException

at org.knopflerfish.framework.bundlestorage.file.Archive.checkNativeLibrary(Archive.java:952)   在org.knopflerfish.framework.BundleClassPath.resolveNativeCode(BundleClassPath.java:493)   在org.knopflerfish.framework.BundleClassPath。(BundleClassPath.java:102)   在org.knopflerfish.framework.BundleClassLoader。(BundleClassLoader.java:158)   在org.knopflerfish.framework.PermissionOps.newBundleClassLoader(PermissionOps.java:302)   在org.knopflerfish.framework.BundleGeneration.resolvePackages(BundleGeneration.java:549)   at org.knopflerfish.framework.BundleImpl.getUpdatedState(BundleImpl.java:1250)   在org.knopflerfish.framework.BundleImpl.finalizeActivation(BundleImpl.java:312)   在org.knopflerfish.framework.PermissionOps.callFinalizeActivation(PermissionOps.java:265)   在org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:295)   在org.knopflerfish.bundle.desktop.swing.Desktop $ 36.run(Desktop.java:2666)

我尝试了很多解决方案,包括one

但似乎没有任何效果,我真的需要帮助,

谢谢

0 个答案:

没有答案