添加一个Equinox OSGI钩子抛出ClassNotFoundException

时间:2013-10-02 12:51:22

标签: java eclipse osgi equinox

我正在尝试在我的OSGi容器中添加一个BundleWatcher挂钩,以便我可以在加载时监视它们。我在config.ini中进行了以下更改,

  1. 在osgi.bundles属性中添加了对jar的引用,如下所示, osgi.bundles =,reference \:file \:../ lib / my.jar@2:start

  2. 设置属性osgi.framework.extensions = mybundle

  3. 在osgi.hook.configurators.include中添加MyBundleWatcher作为钩子

  4. 此外,我的jar文件与OSGi包位于同一目录中。

    当我运行我的应用程序时,我的BundleWatcher得到一个ClassNotFoundException。

    我可以确认我的bundle(包含BundleWatcher)确实已经启动,因为我的bundle中的Activator的start方法被调用。

    我做错了什么?

    作为背景,我接下来是几篇文章,

    http://wiki.eclipse.org/index.php/Adaptor_Hooks

    http://eclipsesource.com/blogs/2013/01/23/how-to-track-lifecycle-changes-of-osgi-bundles/

2 个答案:

答案 0 :(得分:1)

为什么要使用特定于Equinox的BundleWatcher - 需要对Equinox内部和配置的特殊访问 - 而不是OSGi标准BundleTracker,它可以由任何捆绑实现,并且可以在任何框架实现上使用?

答案 1 :(得分:1)

你似乎想要让它变得复杂。您将其作为扩展(如设备驱动程序)并使用专有代码。如果您想要查看安装的所有软件包,可能有一些基本原理,但是当您重新启动时,无论如何都不会看到已安装的软件包的安装事件。因此,如果您能够看到所有捆绑包活跃起来,那么通过最简单的解决方案来跟踪所安装的捆绑包是:

package tracker;
public class Watch implements BundleActivator {
  BundleTracker<Bundle> tracker;

  public void start(BundleContext context) {
    tracker = new BundleTracker<Bundle>( context, -1, null ) {
       public Bundle addingBundle( Bundle b, BundleEvent e) {
          System.out.println("Tracking bundle " + b.getSymbolicName());
          return b;
       }
    };
    tracker.open();
  }

  public void stop(BundleContext context) {}
}

清单:

Bundle-Activator: tracker.Watch