As you may know Apache Felix only supports installing JARs as bundles. But sometimes, as for example during your development, you may want to use the a directory as your bundle packaging format and have Felix allow you to install such a bundle. Usually such a directory is the directory where your sources gets compiled (build directory).
So, if you are in such a need, the new OPS4J Pax URL “assembly:” url handler is for you. Here are the simple ways you can make use of it:
Prepared Apache Felix
First you will need to have Apache Felix installed. I suppose you already have it but if not, follow documentation of Felix site. As I will make use more times of your installation directory, lets name it <felix home>. As for version 1.8.0, after unpacking the distribution files you will get felix-1.8.0 as your <felix home>.
Next you will need the “assembly:” url jar. Download the latest version from project download page or take version 1.1.0 from this direct link. Save the file (or copy afterwards) to <felix home>/bundles directory. As “assembly:” protocol importsConfiguration Admin packages you will have to also install a bundle that has them. You can use Apache Felix Config Admin implementation or just have the OSGi Alliance Compedium API bundle. We will use the former, so download it and save it to <felix home>/bundles (note that Config Admin will become optional starting with next releases of Pax URL).
Next you will have to instruct Felix to load this bundles on start. You do so by changing the configuration file. You will have to edit <felix home>/config/config.properties, look for felix.auto.start.1 and append this lines:
file:bundle/org.osgi.compendium-4.0.1.jar \
file:bundle/pax-url-assembly-1.1.0.jar
Next, start up Felix and you are good to go. Pax URL “assembly:” and “assemblyref:” protocols are now ready to use.
From Apache Felix console
If you do not want to change your Felix setup as abve and just try it out you can achieve the same from Felix console. So, startup Apache Felix and once you are in the console execute the following commands in order to install “assembly:” protocol:
install http://repo1.maven.org/maven2/org/osgi/org.osgi.compendium/4.1.0/org.osgi.compendium-4.1.0.jar
install http://repo1.maven.org/maven2/org/ops4j/pax/url/pax-url-assembly/1.1.0/pax-url-assembly-1.1.0.jar
Pax URL “assembly:” and “assemblyref:” protocols are now ready to use.
Provision via Apache Felix FileInstall
A simple way of provisioning Pax URL “assembly:” protocol is to use FileInstall. If you do not know what is that, find it out from Filippo Diotalevi.
What you will have to do is to copy the two bundles (Pax URL Assembly and OSGi Alliance Compendium) to <felix home>/load (or <felix home>/dropins if you follow Filippo instructions).
Next, start up Felix and, once again, you are good to go. Pax URL “assembly:” and “assemblyref:” protocols are now ready to use.
Provision via Pax Runner
Of course that provisioning this bundles into Felix will be to use Pax Runner. Once you have Pax Runner installed and ready to use, you will not need to download or configure anything. Pax Runner will do that for you with a simple:
pax-run --platform=felix --profiles=url
That’s it. Don’t believe me? Try it out ;). Again you are ready to go with “assembly:” and “assemblyref:” protocols.
Configure java URL protocol handlers
You can transparently make use of Pax URL handlers by configuring Java to discover them. As Felix uses standard Java URL this will also work. But about this maybe some other time in another blog entry.
Using the “assembly” protocols
Now that you have an Apache Felix that knows about “assembly:” and “asemblyref:” protocol you can use them. Lets assume that you have a Maven project somewhere: <my project>. In this case your compiled classes are stored in <my project>/target/classes. What you will have to do to create & instal a bundle containing this classes and any other resource which are in this directory is the following (from Felix console):
install assembly:<my project>/target/classes
That is all. You have now a bundle installed.
I made some assumptions above such as in your build (by using Apache Felix Maven Bundle Plugin or other means), the <my project>/target/classes directory contained an OSGi valid META-INF/MANIFEST.MF. If that is not the case you can make use of Pax URL “wrap:” protocol to automatically generate the OSGi manifest as in:
install wrap:assembly:<my project>/target/classes
If this example of usage is not enough for you there are some much more in the “assembly:” protocol documentation page.