Building OSGI Bundle with Maven Bundle Plugin
This plugin creates a bundle for an OSGI container. It is straight forward to use;however, there are few key features that must be understood. Some features are are not intuitive or is not the same as the meaning in the Java language, for example, does not mean exporting to OSGI container, this means include in the bundle as a part of jar.
Here, I will discuss key features of the plugin. The plugin site has great document and examples to create a configuration for one to build a working OSGI bundle.
<export-package>
—– must be defined and must contain all the packages that you want to be in the bundle jar. Again, it does not mean exporting to OSGI container, this means include in the bundle as a part of jar. This list will be in your class path.<import-package>
——- is for filtering out packages in your source code. This feature allows to slice and dice source code to bundle in different bundles.-
<Import-Package>
——- is for packages that are required by the bundle. The default behavior is all the packages that are referred in the bundle. This header rarely has to be explicitly specified. However, in certain cases when there is an unwanted import, such an import can be removed by using a negation package pattern.
Note that if you have export and private tags, then the export tag takes the precedence.
Issues:
If you have error in bundle deployment in OSGI environment, it is mostly due to issue with correctly building your bundle. The maven bundle plungin sets classpath. So if you do not have correct classpath and correct classes packaged in your JAR, then “ClassNotFound”
exception or similar exception will arise.
If you are using SPRING in OSGI, you may get BeanCreationException
in such case.