Pax TinyBundles
TinyBundles is a library to create and modify OSGi bundles on the fly using fluent Java API.
The API is exposed via an OSGi service TinyBundlesFactory
and static methods in TinyBundles
.
TinyBundles provides two builders to compile bundles: Raw builder and bnd builder.
Bnd builder is calculating and applying a new manifest after analyzing the jar and supports processing of Declarative Services component annotations.
Since TinyBundles 4.0.0 bnd builder is the default.
Using TinyBundles
-
Add TinyBundles dependency
<dependency> <groupId>org.ops4j.pax.tinybundles</groupId> <artifactId>tinybundles</artifactId> <version>4.0.0</version> </dependency>
-
Import
TinyBundles
import static org.ops4j.pax.tinybundles.TinyBundles.bundle;
-
Create an empty TinyBundle
TinyBundle bundle = bundle();
-
Prepare the bundle
-
Optionally fill the bundle up from an existing bundle or plain Java archive
JarInputStream source = new JarInputStream(…); bundle.readIn(source);
-
Set bundle headers and add/remove classes
bundle.setHeader(Constants.BUNDLE_VENDOR, "OPS4J"); bundle.addClass(HelloWorld.class);
-
-
Build the bundle
InputStream inputStream = bundle.build();
TinyBundles is often used with Pax Exam for testing. See TinybundlesTestSupport on how to provision (incl. required dependencies) and DeclarativeServiceBndBundleBuildIT on how to use.
See Examples for more detailed examples showing usage of fluent API.