OSGi Fragments

Appendix E. Useful OSGi tips

E.1. OSGi Fragments

Part of the OSGi R4 release, fragments are a very useful and powerful feature. A fragment is “a bundle that is attached to a host bundle”, adding content to the target bundle. A fragment cannot have its own class loader nor a bundle activator and cannot override the information already present in the host. In short, through fragments, bundles can be extender with resources, classes and even manifest entries. To quote the spec again, a “...key use case for fragments is providing translation files for different locales. This allows the translation files to be treated and shipped independently from the main application bundle.

[Note]Note
For a full description on fragments, please see the OSGi specification, section 3.14.

In Spring-DM, fragments are useful for configuring various components such as the extenders. To do that, simply bundle the resources as you normally would and add an extra entry to the bundle manifest:

Fragment-Host: <host bundle symbolic name>

This line indicates that the containing bundle is a fragment and that it should be attached to the host specified by a symbolic name. The fragment and host bundle symbolic name should be different. For example, to attach a fragment (with extra configuration) the Spring-DM extender, one could use the following manifest:

Manifest-Version: 1.0                                                                    (1)
Bundle-ManifestVersion: 2                                                                (2)
Fragment-Host: org.springframework.bundle.osgi.extender                                  (3)
Bundle-SymbolicName: org.mydomain.project.fragment                                       (4)
Bundle-Name: my-fragment                                                                 (5)
Bundle-Description: Fragment attached to Spring-DM extender                              (6)
1

Manifest version.

2

OSGi bundle version. A value of 1 (which is also the default) indicates an OSGi Release 3 bundle so it's best to specify 2 to indicate an OSGi Release 4 bundle.

3

The symbolic name of the bundle to which this fragment should be attached to. In this case, the value org.springframework.bundle.osgi.extender points to the spring-osgi-extender.jar. Fragment-Host is the key entry which tells the OSGi platform that the containing bundle is a of a special kind - it's a fragment.

4

The fragment symbolic name.

5

The bundle name - an optional yet useful header.

6

The bundle description - just like the name, this header is useful for humans not for the OSGi platform itself. However, it is recommended that you define it to help identify the bundle purpose.

[Note]Note
The Manifest entries order does not matter, but they case sensitive.

When multiple bundles with the same symbolic names are present, one can add the bundle version to make sure the proper wiring is done:

Fragment-Host: org.springframework.bundle.osgi.extender;bundle-version=1.1.0

The default value for bundle-version (when it's not specified) is [0.0.0,∞)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值