What is OSGi fragment?
OSGi fragment is the java archive file or jar file or bundle, which have some classes, resource and header. The purpose of fragment to develop an extension of a bundle, which add on additional functionality and merge those functionality with host bundle at the time of host bundle is getting resolve. Before host bundle get resolved fragment appended to host. Following are the key points which we need to keep in mind while working with OSGi fragment.
- Fragment is treated as part of the host bundles.
- A fragment cannot have its own class loader or bundle activator.
- Fragment bundle cannot override the information present in the host bundles.
- Both host and fragment share the same class loader from host bundle.
- An OSGi fragment doesn't have it life-cycle and that means we can't activate, start, stop a fragment.
- All classes and definition of fragment are merged with host definition when the host bundle get resolved. If the fragment dependencies cannot be resolved, the fragment does not attach to the host bundle.
- If any information from host and fragment conflicts then fragment will not attach and merge with host bundle.
- Fragments extend host bundles with resources, classes, and permitted headers.
- Fragments can only add new files, and does not replace or override existing files from host.
- OSGi fragment JAR file contains manifest file which have host bundle information.
- Fragment jar cannot be use independently.
- Fragments bundles could you attached with one or many host bundles.
Why do we have fragments and what is the role of fragments and why we use?
- To provide the extra classes or additional functionality to host bundle.
- Add configuration files and properties.
You can create a fragment project using eclipse.
To create an OSGi fragment project in Eclipse follow the below steps:
- Go to File >> New >> Other >> Plug-in Development >> Fragment Project
- Select Fragment project and click on the next.
- Put a valid project name for your fragment and then click on next button.
- Now under the Host plun-in section, put the host bundle name in plug-in ID field.
Here is the complete step by step guide to create an OSGi fragment project using Eclipse. >> https://rashidjorvee.blogspot.com/2019/03/how-to-create-osgi-fragment-project.html
No comments:
Post a Comment