Eclipse RCP:根据资源请求激活包
Eclipse RCP: bundle activation upon resource request
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
(或 Equinox 3.4+ 中的 Bundle-ActivationPolicy: lazy
),bundle 将在第一个 class 或资源 [=29 时被激活=] 请求。
最初我想问的是如何将资源文件添加到激活例外列表中,因为根据文档,例外列表仅包含 class 个包:
Bundle-ActivationPolicy: lazy; exclude:="org.eclipse.foo1, org.eclipse.foo2"
但后来我 运行 进行了几次测试,发现资源请求未激活捆绑包 - 只有 class 请求激活了捆绑包。我能够访问我的资源文件并读取其内容而无需触发包 Activator.start。
所以问题是:
- 是否根据资源请求激活捆绑包?如果不是,则文档似乎具有误导性。
- 如果正在激活,如何将非java文件添加到exclude/include列表中?为什么 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.
(2014 年 6 月 6 日 OSGi 核心版本 4.4.6.2 部分)
也就是说资源永远不会触发激活。
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
(或 Equinox 3.4+ 中的 Bundle-ActivationPolicy: lazy
),bundle 将在第一个 class 或资源 [=29 时被激活=] 请求。
最初我想问的是如何将资源文件添加到激活例外列表中,因为根据文档,例外列表仅包含 class 个包:
Bundle-ActivationPolicy: lazy; exclude:="org.eclipse.foo1, org.eclipse.foo2"
但后来我 运行 进行了几次测试,发现资源请求未激活捆绑包 - 只有 class 请求激活了捆绑包。我能够访问我的资源文件并读取其内容而无需触发包 Activator.start。
所以问题是:
- 是否根据资源请求激活捆绑包?如果不是,则文档似乎具有误导性。
- 如果正在激活,如何将非java文件添加到exclude/include列表中?为什么 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.
(2014 年 6 月 6 日 OSGi 核心版本 4.4.6.2 部分)
也就是说资源永远不会触发激活。