The Eclipse-LazyStart header is used to specify if a bundle should be started before the first class or resource is accessed from that bundle
取自Eclipse官方documentation .
从这句话可以推断,如果指定Eclipse-LazyStart
(或 Bundle-ActivationPolicy: lazy
在 Equinox 3.4+ 中)该 bundle 将在第一类或资源请求时激活。
最初我想问如何将资源文件添加到激活异常(exception)列表中,因为根据文档,异常(exception)列表仅包含类包:
Bundle-ActivationPolicy: lazy; exclude:="org.eclipse.foo1, org.eclipse.foo2"
但是后来我运行了一些测试,发现 bundle 没有在资源请求时被激活 - 只有类请求才会激活 bundle 。我能够访问我的资源文件并读取其内容,而无需触发 bundle Activator.start。
所以问题是:
- 是否根据资源请求激活 bundle ?如果不是,则说明文档具有误导性。
- 如果正在激活,如何将非 java 文件添加到排除/包含列表中?为什么 Activator.start 没有被触发?
最佳答案
Bundle-ActivationPolicy
的实际 OSGi 规范说:
By default, any class loaded from the bundle can trigger the lazy activation, however, resource loads must not trigger the activation. The lazy activation policy can define which classes cause the activation with the following directives:
• include - A list of package names that must trigger the activation when a class is loaded from any of these packages. The default is all package names present in the bundle.
• exclude - A list of package names that must not trigger the activation of the bundle when a class is loaded from any of these packages. The default is no package names.
(第 4.4.6.2 节 OSGi 核心版本,2014 年 6 月 6 日)
这就是说资源永远不会触发激活。
关于Eclipse RCP : bundle activation upon resource request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36007279/