Quick OSGi projects using Maven archetypes
Have you ever wanted to try OSGi, but found setting up the build and working out the manifest too much of a chore?
If so then help is at hand - over the last few months, I have been developing a set of Maven archetypes and plugins to automate much of the manual work required in creating an OSGi project. Recently I also provided Windows batch files and Linux shell scripts to make it even easier:
http://wiki.ops4j.org/confluence/display/ops4j/Pax+Construct
All you need is Maven2 and a Java5 runtime - the best part is the OSGi manifest attributes are automatically calculated for you by Peter Krien's wonderful bnd tool, connected to Maven by the maven-bundle-plugin from the Apache Felix project.
For example, the following commands would create a simple skeleton OSGi web application ... and deploy it to Equinox:
pax-create-project -g simple.project -a osgi-web-app
cd osgi-web-app
mvn install
pax-wrap-jar -g javax.servlet -a servlet-api -v 2.5
pax-import-bundle -g org.ops4j.pax.logging -a api -v 0.9.4
pax-import-bundle -g org.ops4j.pax.logging -a jcl -v 0.9.4
pax-import-bundle -g org.ops4j.pax.logging -a slf4j -v 0.9.4
pax-import-bundle -g org.ungoverned.osgi.bundle -a http -v 1.1.2
pax-create-bundle -p my.osgi.code.myBundle -n myBundle
mvn install pax:provision
all you need to add is the internal application code ;)
2 comments:
Nice post. Would be even better if it had some comments on what each of the pax-* line is doing, making it clearer to the not-so-experienced
Yep :)
This was written some time ago to give a flavour of what was possible. Since then there's more doc available here and a more detailed example with comments here.
Post a Comment