无法解决 OSGI 未解决的要求:导入包:org.osgi.service.event

Can not resolve the OSGI Unresolved requirement: 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)) );
    }

}

和我的项目结构

我做错了什么?

您的包裹似乎没问题。您只是在运行时缺少包 org.osgi.service.event 的提供者。尝试安装捆绑包 equinox Eventadmin 或 Felix Eventadmin。