tags:

views:

805

answers:

5

I have a server application that consists of multiple OSGi bundles, some mine, some third-party. One of the bundles provides a web frontend using Struts. The necessary Struts libraries live inside the web front-end bundle.

Now I want to add a second bundle that provides another web front-end, with different dependencies and a very different use case. I want to use Struts for that bundle, too, but I don't want to put the same libraries into two bundles.

With OSGi, it should be no problem to separate the Struts libs in a bundle of their own and use that from both my bundles. However, I couldn't find Struts packaged that way.

Some quick googling and a look at the Struts homepage didn't yield anything. I could find a plugin for Struts to run an OSGi container inside Struts, but that's not what I want.

A: 

Is this what you are looking for?: http://cwiki.apache.org/S2PLUGINS/osgi-plugin.html

Praveen Angyan
No, that's the other way around: it starts an OSGi container (Apache Felix) from inside Struts.
Hanno Fietz
A: 

Struts is a framework for the Servlet Container (distributed component architecture). oSGI is also a distributed component architecture.

I think your best bet may be to take a look at oscar http service and based on oscar's code see how they have mapped the oscar HttpService, context, etc. to jetty servlet container. And then port the struts framework to run on top of the embedded jetty.

That approach is actually really complicated.
Hanno Fietz
+5  A: 

Take a look at the current struts bundles on http://repo2.maven.org/maven2/org/apache/struts/struts2-core/2.1.6/.

If you download struts2-core-2.1.6.jar for example, extract it and take a look at META-INF/MANIFEST.MF you'll see that it does contain OSGI headers (Import-Package, Export-Package, Bundle-*):

C:\TMP\META-INF>more MANIFEST.MF
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: 1.5.0_10 (Sun Microsystems Inc.)
Built-By: musachyb
Build-Jdk: 1.5.0_10
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Import-Package: com.opensymphony.xwork2;version="2.1",com.opensymphon
 <SNIP>
Bnd-LastModified: 1231185746365
Export-Package: org.apache.struts2.views.xslt;uses:="javax.servlet.ht
Bundle-Version: 2.1.6
 <SNIP>
Bundle-Description: Apache Struts 2
Bundle-Name: Struts 2 Core
Bundle-DocURL: http://www.apache.org
Bundle-ManifestVersion: 2
Bundle-Vendor: Apache Software Foundation
Bundle-SymbolicName: org.apache.struts.struts2-core
Tool: Bnd-0.0.255

No idea how you go about using them within an OSGi app - but in theory you can atleast reference them and do "stuff"!! :)

Martin
Actually, what this means is yes, Struts is available as an OSGi bundle :)
Hanno Fietz
And the Spring repository (www.springsource.com/repository) is always a good place to look for common Java libraries that have already been wrapped with the correct OSGi headers.
hbunny
A: 

take a look at these links, i hope you find them a little helpful don brown's web blog

and read this article it may be helpful java lobby: Modularizing existing web applications with OSGi

well i think you would have to make the wrapping task yourself .

sazamsk
Sorry, both of these articles are about doing it the other way around, running an OSGi container in a web application. I have a server-side OSGi application with a web front-end that uses Struts and now I want to add a second, different front-end that also uses Struts, without putting the same Struts-JARs in both bundles.
Hanno Fietz
A: 

Using Maven, it is very easy to create an OSGi bundle from any library. Since Struts is already available as an OSGi-Bundle in the central Maven repository (see accepted answer), I put that solution in a separate question & answer post.

Hanno Fietz