OSGI bundle 动态更新

来源:互联网 发布:js 文字字数限制 编辑:程序博客网 时间:2024/05/29 05:57

http://blog.csdn.net/saloon_yuan/article/details/7902569

在这篇文章中提到bundle update后,要经过refresh的操作才能完成成真正的更新。

在使用eclipse equinox开发osgi应用的过程中,发现在Bundle类中提供了update的接口,但没有提供refresh的接口,只能在osgi控制台输入refresh+bundleID来执行refresh操作。

那么如何通过java代码来执行refresh操作呢?

后来在EclipseStarter的API中发现其提供了一个refreshPackages的静态私有方法,那么只要通过反射取到这个方法就能执行bundle的refresh的操作了:

bundle.update();Method method=EclipseStarter.class.getDeclaredMethod("refreshPackages",new Class[]{Bundle[].class});method.setAccessible(true);method.invoke(null, new Object[]{new Bundle[]{bundle}});


0 0
原创粉丝点击