-
Notifications
You must be signed in to change notification settings - Fork 2
Configuring bundle plugin
When using the Apache Felix Bundle Plugin you need to configure to export the required libraries. This page attempts to describe the process of configuring and running the bundle plugin. In our attempt, we encountered issues, which we describe here and we will explain what we did to solve them.
This description is based on our attempt to configure the pubsub with Felix.
When using the command mvn package
, by default there is no OSGi bundle created. It would then be required to run mvn bundle:bundle
. Adding <packaging>bundle</packaging>
to the <project>
element this bundling is done automatically. We added this underneath <artifactId>
.
In the <Export-Package>
element you add packages that the bundle should export. This is your own code that needs to be included in the bundle and can be used when your package is required by other packages.
In the <Embed-Dependency>
element you add required dependencies. We have two examples.
api;groupId=org.inaetics.dronessimulator.pubsub;scope=compile|runtime
This first example is a local module that we require to be available. The module as the artifactId api
, but since this could be too general we specified the groupId aswell. We only include these dependencies if they are needed during compilation or at runtime.
amqp-client;scope=compile|runtime
This second example includes the rabbitmq library. This library has a distinctive name and thus we did not include the groupId. This one is also embedded only during compilation or at runtime.
The <Embed-Transitive>
should, when set to true, embed any dependencies a dependency itself depends on. It should recursively add all required dependencies.
During the time we spend fixing issues, we found that this tag did not do anything.
The <Import-Package>
instruction is a list of packages that are required by the bundle's contained packages. If there are unused or unwanted packages it is possible to remove these. This can be done by using the negation sign (exclamation sign) !com.codahale.metrics,!org.slf4j.impl,*
.
In our case we had a optional dependency for RabbitMQ, codale.metrics which we did not use. In the RabbitMQ pom this was optional, and thus if it was not used, this was neither included. However, Felix still wants this package, since it will be imported automatically. To solve this, we excluded this from the Import-Package.
The <Private-Package>
instruction is a list of packages which are added to the jar but are not exported by the bundle. This is useful when you need code-dependencies but do not want to export them or embed a jar.