首页 > 解决方案 > 无法解决 OSGI 未解决的要求:Import-Package: org.osgi.service.event

问题描述

我正在尝试运行 OSGI 捆绑包,但总是收到错误消息Unresolved requirement: Import-Package: org.osgi.service.event

我正在使用带有 OSGI 插件的 IntelliJ

有我的 MANIFEST.MF 文件看起来像

Manifest-Version: 1.0
Bundle-Activator: com.project.g.Publisher
Bundle-ManifestVersion: 2
Bundle-Name: pubs
Bundle-SymbolicName: pubs
Bundle-Version: 1.0.0
Bundle-ClassPath: lib/org.osgi.service.event-1.3.1.jar
Export-Package: com.project.g;uses:="org.osgi.framework";version=
 "1.0.0"
Import-Package: org.osgi.service.event,org.eclipse.osgi.util,org.apache.felix.gogo.command,
 org.osgi.framework,
 org.osgi.util.tracker

代码(来自示例)

public class Publisher extends Thread implements BundleActivator {
    Hashtable time = new Hashtable();
    ServiceTracker tracker;

    @Override
    public void start(BundleContext bundleContext) throws Exception {
        System.out.println("started");
        tracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(), null );
        tracker.open();
        start();

    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {
        System.out.println("stopped");
    }

    public void run() {
        while ( ! Thread.interrupted() ) try {
            Calendar c = Calendar.getInstance();
            set(c,Calendar.MINUTE,"minutes");
            set(c,Calendar.HOUR,"hours");
            set(c,Calendar.DAY_OF_MONTH,"day");
            set(c,Calendar.MONTH,"month");
            set(c,Calendar.YEAR,"year");

            EventAdmin ea =
                    (EventAdmin) tracker.getService();
            if ( ea != null )
                ea.sendEvent(new Event("event/start", (Map<String, ?>) time));
            Thread.sleep(60000-c.get(Calendar.SECOND)*1000);
        } catch( InterruptedException e ) {
            return;
        }
    }

    void set(Calendar c, int field, String key ) {
        time.put( key, new Integer(c.get(field)) );
    }

}

和我的项目结构

在此处输入图像描述

在此处输入图像描述

我在这里做错了什么?

标签: osgiosgi-bundle

解决方案


您的捆绑包似乎很好。您只是在运行时缺少包 org.osgi.service.event 的提供者。尝试安装捆绑包 quinox Eventadmin 或 Felix Eventadmin。


推荐阅读