Easy OSGi provisioning with Pax-Runner provisioning files
|
As Craig reminded me in a comment some days ago, the best way to provision non-trivial OSGi applications with Pax Runner is to write a custom profile or a provisioning file. In this tutorial we will go through all the steps you need to do in order to write your own provisioning file. First of all, why do you need provisioning files? The main advantage is that the combination of Pax-Runner, basic profiles and provisioning files allows to completely automate the deployment of your OSGi-based application. For example, you can deploy your OSGi based web application in your server farm just launching a simple command like pax-run.sh --profiles=web http://myrepository/web.txt in all the nodes of your cluster. |
![]() Want to learn more on Pax-Runner? Read Starting with OSGi? Try Pax-Runner! |
Let’s start by saying that a provisioning file can be as simple as a list of bundles. Let’s make a useful example building a provisioning file to install the Apache Felix Application Demo. These bundles are not available for download in the Felix website, so I uploaded a copy of them in the OSGi Look server.
Now just open any text file and type:
http://www.osgilook.com/static/samples/servicebased.circle-1.0.0.jar http://www.osgilook.com/static/samples/servicebased.host-1.0.0.jar http://www.osgilook.com/static/samples/servicebased.square-1.0.0.jar http://www.osgilook.com/static/samples/servicebased.trapezoid-1.0.0.jar http://www.osgilook.com/static/samples/servicebased.triangle-1.0.0.jar
Save the file as felix-demo.txt.
Now go back to your console, and type pax-run.sh file:///path/to/felix-demo.txt.
pax-run.sh file:////tmp/demo.txt
______ ________ __ __
/ __ / / __ / / / / /
/ ___/ / __ / _\ \ _/
/ / / / / / / _\ \
/__/ /__/ /__/ /_/ /_/
Pax Runner (1.1.1) from OPS4J - http://www.ops4j.org
----------------------------------------------------
-> Using config [classpath:META-INF/runner.properties]
-> Using only arguments from command line
-> Scan bundles from [file:////tmp/demo.txt]
-> Scan bundles from [scan-file:file:////tmp/demo.txt]
-> Provision bundle [http://www.osgilook.com/static/samples/servicebased.circle-1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache]
-> Provision bundle [http://www.osgilook.com/static/samples/servicebased.host-1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache]
-> Provision bundle [http://www.osgilook.com/static/samples/servicebased.square-1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache]
-> Provision bundle [http://www.osgilook.com/static/samples/servicebased.trapezoid-1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache]
-> Provision bundle [http://www.osgilook.com/static/samples/servicebased.triangle-1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache]
-> Preparing framework [Felix 1.8.1]
-> Downloading bundles...
-> http://www.osgilook.com/static/samples/servicebased.circle-1.0.0.jar : 12051 bytes @ [ 45kBps ]
-> http://www.osgilook.com/static/samples/servicebased.host-1.0.0.jar : 386419 bytes @ [ 51kBps ]
-> http://www.osgilook.com/static/samples/servicebased.square-1.0.0.jar : 10705 bytes @ [ 40kBps ]
-> http://www.osgilook.com/static/samples/servicebased.trapezoid-1.0.0.jar : 12018 bytes @ [ 89kBps ]
-> http://www.osgilook.com/static/samples/servicebased.triangle-1.0.0.jar : 11993 bytes @ [ 65kBps ]
-> Using execution environment [J2SE-1.6]
-> Runner has successfully finished his job!
Welcome to Felix.
=================
->
The logs show that all the bundles listed in the provisioning file are installed and started in your Felix container. And after a few seconds, you will be able to play with the Apache Felix Demo application!

Provisioning from a URL
If you want to use your provisioning file to startup multiple instances of an application, the best thing you can do is to upload it in a HTTP server. For instance, you can find the provisioning file we have just written at http://www.osgilook.com/static/samples/felix-demo.txt.
You can try now to type pax-run.sh http://www.osgilook.com/static/samples/felix-demo.txt: as a result, you will create a Felix container and automatically download all the bundles defined at that URL.
Advanced features
Pax-Runner provides many advanced features; you can for instance set start levels, use different protocols (Maven) and set system properties. Please refer to the documentation for a complete overview.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

