Blogs

SpringSource Blog

Deploying WARs to the OSGi Web Container is now even easier

Andy Wilkinson

As Rob mentioned in his introduction to the OSGi Web Container, dm Server automatically imports system packages into Web bundles. This has proved very useful, especially when deploying existing WAR files into an OSGi environment. I've recently spent some time moving this functionality from dm Server's Web subsystem into the OSGi Web Container RI. This blog describes the new functionality, and how to make use of it.

Enabling import of the system packages

There are two ways in which you can instruct the RI to import all of the exported system packages.

When you install a Web bundle, you can now use the SpringSource-SystemPackages URL parameter to automatically import all of the system bundle's exports. For example:

install webbundle:file:mywar.war?SpringSource-SystemPackages=import

Alternatively, if you'd prefer not to have to remember to specify the parameter each time you install the WAR file, you can enable this functionality by adding the SpringSource-SystemPackages header to your WAR's manifest:

SpringSource-SystemPackages: import

Which packages are imported?

The RI will generate an import for every package that's exported by the system bundle, unless the WAR file already imports the package, or contains the package in WEB-INF/classes or within a Jar in WEB-INF/lib. If the WAR file already imports or contains the package, the system bundle's export is ignored, and any existing import is left untouched. In the case where a new import is generated, it is generated with a version range that precisely encompasses the version(s) exported from the system bundle.

Trying it out

Firstly, build and launch the RI as Rob previously described, with the exception that, if you've used a previous version of the RI, you should start PAX runner with the clean option to ensure that it uses the newly-built RI bundles rather than those in its cache:

pax-run --clean --platform=equinox --snapshot runner.bundles

Previously, to successfully use the formtags WAR, it was necessary to import a handful of packages using the Import-Package URL parameter:

install webbundle:file:formtags.war?Import-Package=org.xml.sax,org.xml.sax.helpers,javax.xml.parsers,org.w3c.dom

This is a little cumbersome as you need to know which packages to import. Instead, you can now use the SpringSource-SystemPackages URL parameter:

osgi> install webbundle:file:formtags.war?SpringSource-SystemPackages=import
Bundle id is 43

Without there having been the need to list specific packages to import when the formtags Web bundle was installed, it should now start successfully:

osgi> start 43

What's next?

We've been working on a prototype for truly modular OSGi Web applications and we're getting tantalisingly close to having something to show you. It'll be in the form of a new component for dm Server, running on top of the OSGi Web container that dm Server now embeds in place of its previous web support. All being well it should be ready by the end of the week. Watch this space!

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • Twitter
 

8 responses


  1. Will you by any chance attend Jazoon in Zurich next week? I'd really like to give this a try and discuss it until then.


  2. The dm server development snapshots builds have doubled in size (around 51 MB from 25 MB) recently with all files getting duplicated. You might want to look into this.


  3. @Pierre-Antoine, no, unfortunately not. However, a number of other SpringSource employees will be at Jazoon – grab one of them and they'll be happy to discuss this with you. Alternatively, you can post any questions you have on the dm Server forums.

    @Anoop Thanks. This should now be fixed in 2.0.0.CI-R315-B264.zip and later.


  4. When I am trying to evaluate with the snapshots builds 264 to 266 ,during deployment of a war file I got javax.management.MalformedObjectNameException: Invalid character ':' in value part of property execption.You might want to look into this


  5. @Mahesh, thanks for reporting this. I assume you're referring to the dm Server snapshot builds? If you have a moment, could please open a JIRA for the problem that you're seeing?


  6. Has anyone looked into why either the RI or pax-run does not honor proxies? Even when I use the proper

    -Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=80

    I still get the build bombing out.


  7. Any news on how to configure the Tomcat instance yet? Especially when not running the web container in Spring dm. When I create my own OSGi container based on equinox, how do I configure the tomcat server.xml so that I can set connector properties and keystore locations, etc.?


  8. Don, the configuration location algorithm used by the com.springsource.osgi.webcontainer.tomcat bundle is as follows:

    1. Check for config/tomcat-server.xml in the current working directory, use if found
    2. Check this bundle and attached fragments for /META-INF/tomcat/server.xml, use if found
    3. Check this bundle for /META-INF/tomcat/default-server.xml, use if found
    4. Throw IllegalStateException if no configuration is found

    Take a look at com.springsource.webcontainer.tomcat.TomcatConfigLocator for the implementation. The server.xml file is a standard Tomcat server.xml and you be used to configure connectors, keystore locations, etc.

One trackback

Leave a Reply