Question

I am trying to create war hosting OSGi bundles. The complete configuration should be able to host WAB bundles, and now I try to integrate pax-web-extender-war for that. It requires some dependencies like slf4j-api and slf4j-log4j12 and here is the problem: I always get this exception:

org.osgi.framework.BundleException: Fragment bundles can not be started.
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1782)

because slf4j-log4j12 is really a fragment bundle. I assumed Felix should cope with this but it does not. So I tried to move this jar to WEB-INF/lib but then wiring fails as osgi cannot resolve it as a bundle.

So,

  • Where should I put fragment bundles ?
  • Should it be somehow configured in framework.properties ?
  • is Apache Felix even capable of working with fragment bundles ?

Following is current layout of the war (note that it is based on felix http bridge sample):

.
└── WEB-INF
    ├── bundles
    │   ├── commons-fileupload-1.2.2.jar
    │   ├── commons-io-2.4.jar
    │   ├── hello-wab-1-SNAPSHOT.war
    │   ├── org.apache.felix.http.bridge-2.2.0.jar
    │   ├── org.apache.felix.http.samples.filter-2.2.0.jar
    │   ├── org.apache.felix.webconsole-4.0.0.jar
    │   ├── pax-web-api-2.1.0.jar
    │   ├── pax-web-extender-war-2.1.0.jar
    │   ├── pax-web-spi-2.1.0.jar
    │   ├── slf4j-api-1.6.6.jar
    │   ├── slf4j-log4j12-1.6.6.jar
    │   └── wrapper-json-1-SNAPSHOT.jar
    ├── classes
    │   └── org
    │       └── apache
    │           └── felix
    │               └── http
    │                   └── samples
    │                       └── bridge
    │                           ├── FrameworkService.class
    │                           ├── ProvisionActivator.class
    │                           └── StartupListener.class
    ├── framework.properties
    ├── lib
    │   ├── org.apache.felix.framework-4.0.3.jar
    │   ├── org.apache.felix.http.proxy-2.2.0.jar
    │   ├── org.apache.felix.webconsole-4.0.0.jar
    │   ├── org.osgi.compendium-4.3.0.jar
    │   └── wrapper-json-1-SNAPSHOT.jar
    └── web.xml
Was it helpful?

Solution

I suggest adding pax-logging to your bundles, it'll keep away the pain of logging in the OSGi world. Pax-Logging

For the fragment-bundles you just need to add them to the usual bundles. I'd say in your setup probably in the bundles folder. Since it's a fragment bundle the Exception you get is right, it's not a "startable" bundle. It will only resolve and hopefully attached to the hosting bundle.

By the way, Felix is capable of working with fragment bundles :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top