Red Hat
Dec 28, 2015
by Christina Lin
Now that JBoss Fuse supports both OSGi Karaf and JavaEE JBoss EAP container. When to use which one, is there any best practice for which container to use? And same as the answer as any other software related question, well, any questions in life actually. "it depends" .... Situation varies between cases, here are my point of view, you many like it or disagree, I am very happy to hear more of your thoughts.

Here is the thing, I think, it is BEST if you stick with Karaf container if possible for now. It is more light weight, which means you can deploy application much more quickly and expend faster horizontally with application distributed everywhere. And the may OSGi manages the lifecycle of the services allows you to dynamically deploy and undeploy service without affecting the others service in the same container. That, is very important in for mission critical services. So if you get to choose which ever to use go with Karaf.
What I also believe is, in an enterprise you should not be restricted to use Single kind of container, different container framework exist for a reason. Especially if you are providing a web application with EJB, JARs complex application glue together to serve as the core business for the web application. Maybe it's a legacy application that has everything done in the Application server. Or it simply has too many non-OSGi compatible libraries to work with. Then I will go for the JBoss EAP scenario.

So how to move from OSGi to JavaEE container or vise versa? Moving a bundle from OSGi to JavaEE is dead simple. But please note, use the Spring framework instead of Blueprint, if you are using OSGi, I would first convert it Spring then work with it.

In this case I will be using a WAR application, since most people use this format in JavaEE and it is supported in Karaf as well.

So there are few ground rules if you want to switch back and forth between the containers, is


  • Use Spring Framework
  • Make sure your Camel route is placed under META-INF under webapp and named *-camel-context.xml

  • Set you plugins to generate metadata needed for OSGi container.
    • Add maven-bundle-plugin        
       <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.3.7</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>bundle-manifest</id>
            <phase>process-classes</phase>
            <goals>
              <goal>manifest</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <supportedProjectTypes>
            <supportedProjectType>jar</supportedProjectType>
            <supportedProjectType>bundle</supportedProjectType>
            <supportedProjectType>war</supportedProjectType>
          </supportedProjectTypes>
          <instructions>
            <Bundle-SymbolicName>camel-blueprint</Bundle-SymbolicName>
            <Private-Package>com.redhat.springtest</Private-Package>
            <Import-Package>*</Import-Package>
          </instructions>
        </configuration>
       </plugin>

By sticking with these rules will allow you to create a project that can deploy on both containers.
In JBoss Fuse Karaf Container,

  • Install with Profile or using OSGi command, 
    • war:mvn:com.redhat/springtest/1.0.0-SNAPSHOT/war?Web-ContextPath=springtest
  • Make sure to have feature-fabric-web profile in your container

Running JBoss EAP Container with Fuse application.

  • Deploy and install by
    • Drag and drop the WAR file under deployment folder
    • Using Console/CLI deployment
  • Make sure Fuse subsystem is installed and activated. 
  • Remember to disable ContextLoaderListener in web.xml

Here is a video showing how to move application between containers.
Original Post