2

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
Petr Kozelka
  • 7,670
  • 2
  • 29
  • 44

1 Answers1

1

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 :)

Achim Nierbeck
  • 5,265
  • 2
  • 14
  • 22
  • how is this related to my question ? – Petr Kozelka Nov 11 '12 at 13:00
  • Well adding pax-logging to your stack surely improves your issue, instead of trying with a fragment for configuring, use pax-logging in conjunction with configuration-admin-service to configure your logging. And it'll give the opportunity to also use other different logging frameworks and all will log into the same logfile. – Achim Nierbeck Nov 11 '12 at 20:48
  • I see, this seems to be addressing the logging problem, but the question is about working with fragment bundles in general. Anyway, I tried to add pax-logging, with no success - the referenced docs is not very informative. Could you please be more specific on how to add it ? Plus, preferably, I would like to know how to use fragment bundles with felix... – Petr Kozelka Nov 12 '12 at 15:44
  • 2
    Added hopefully some more info about the fragments, one question though do you really need to deploy the OSGi runtime in a Web-Container, only to server Web-Content? Why not use a OSGi-Container capable of serving Web-Content, as Apache Karaf for example, and by the way your logging issue will be gone with that also :) – Achim Nierbeck Nov 13 '12 at 13:28
  • thanks for the added info, maybe Felix just prints exception but actually handles it, will have to check... Concerning your question, this project is rather synthetic, just to isolate and demonstrate the problem. The place where I actually face it is far more complex project, where I am very limited in technological choices. – Petr Kozelka Nov 13 '12 at 14:50
  • yes, felix should only print the warning but still resolve the fragment bundle. About the limited technology choices, yes I heard that quite often now, it's a real pity since it's not really needed. One thing that I'm curious about is, how good does the pax-web-extender work with the felix httpserver, why not stick to the complete pax-web stack? – Achim Nierbeck Nov 13 '12 at 17:22