2
votes

I have one struts2 application which is running Apache Felix OSGi in embedded mode. Is it possible to expose jar files in main webapp to the OSGi bundles? Otherwise I will have to deploy same jar file twice once include in webapp classpath for the main application and once more deployed as bundle inside embedded Felix OSGi container.

1

1 Answers

2
votes

Yes. You can certainly do this. But, there are known issues with embedding an OSGi container within a webapp. The arise from the fact that the classloader context of the webapp is non-standard. I've been working with an app that does exactly the same thing. If I was able to write the app from scratch, I would NOT do it this way. I would, instead, deploy Struts2 as an OSGi bundle itself, along with everything else. In other words, I'd embrace the OSGi modularized runtime completely.

With that being said, the OSGi container is itself a bundle and can export packages just like any bundle. It's known as the "system bundle" and you can specify packages from the "host" application's classloader as packages to export into the OSGi container via the system bundle.

See the example on this page, and search for this configuration parameter.

Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA

This config parameter contains a list of packages from the host app's classloader that should be available to your osgi bundles.

As for the "issues", see these links as a start:

A good description of the embedded in a webapp dangers.

Specifics about classloader issues.