Skip to content

Karaf-assembly and features: new and old method?

I am attempting to create a Java Maven OSGI Desktop Application which can be launched using Karaf. The project includes several bundles. I believe I need to create features and assemble them?

From Karaf’s documentation it seems there is a new and “old” way. https://svn.apache.org/repos/asf/karaf/site/production/manual/latest/custom-distribution.html I am still confused about the following:

  1. In addition to my parent/child bundle projects, should there be a Features and an Assembly project with their own pom.xml(s)? I am unsure of the overall structure and found varying karaf examples.

  2. Should features.xml be generated automatically (by a plugin) or manually created?

  3. In the case there should be a Features project, should it have <packaging>features</packaging> or<packaging>pom</packaging>

  4. For my goal, is there any need for karaf blueprint/camel?

Thank you

Answer

  1. In addition to my parent/child bundle projects, should there be a Features and an Assembly project with their own pom.xml(s)? I am unsure of the overall structure and found varying karaf examples.

Most examples generally see people use structure like this for osgi-applications (basically group of bundles that work together to provide a service).

  • Parent project
    • API bundle(s)
    • Implementation bundle(s)
    • Feature repository project

Use of features for own projects is optional but generally recommended as installing individual bundles along with their dependencies gets increasingly more tedious the more bundles you have. With features you can group bundles, their dependencies (including features) and default configurations which makes installing, uninstalling and updating OSGi applications a lot easier.

  1. Should features.xml be generated automatically (by a plugin) or manually created?
  2. In the case there should be a Features project, should it have

As for including assembly project depends on ones preference. However based on separation of concerns one could include the assemply project to the related parent project if the said karaf instance is only running just one osgi application where as if its running multiple it’s probably best to keep it separate from OSGi applications or include it under some project including bundles that contain generic tools, models and services that are used my multiple OSGi applications running inside karaf.

For creating features.xml you should use the official karaf-feature-archetype org.apache.karaf.archetypes/karaf-feature-archetype/<karaf-version> which provides you with pre-configured project where you can just start adding feature definitions. With it you can generate features.xml file using e.g mvn install command. More about available archetypes in the documentation.

Projects generated by the official archetype use <packaging>features</packaging>.

  1. For my goal, is there any need for karaf blueprint/camel?

Depends if you need the integration capabilities of Apache camel for your application. You can also use blueprints without camel or alternatively use declarative services.

As for desktop applications don’t know how well they’re supported in karaf. Most common use cases I’ve seen are related to running backend stuff like web-services, integrations, scheduled tasks etc.