7.3 Form Tags Shared Libraries WAR

As mentioned above, a standard WAR file typically packages of all its required dependencies in WEB-INF/lib. The servlet container will then add all of the JARs in WEB-INF/lib to the application's classpath.

The first step of the migration towards benefiting from an OSGi container is to continue using a WAR but retrieve the dependencies from the dm Server's bundle repository at runtime. This can significantly reduce the time it takes to build and deploy the application. It also enables the enforcement of policies regarding the use of third-party libraries.

The way in which dependencies are declared in an OSGi environment is via manifest headers in a bundle's /META-INF/MANIFEST.MF. As mentioned in Chapter 5, Developing Applications, there are three ways of expressing dependencies: Import-Package, Import-Bundle and Import-Library.

The Form Tags application uses JSTL standard tag libraries. Thus, you need to choose a JSTL provider, for example the Apache implementation which comes with the dm Server. To use the Apache implementation of JSTL, you need to express your dependency as outlined in the following manifest listing. Because it is a single bundle, Import-Bundle is the simplest and therefore preferred manifest header to use.

The Form Tags application requires commons-logging and Spring. It would be very painful to have to list all the Spring packages one by one. Equally, considering the number of bundles that make up the Spring framework, it would be verbose to list each bundle. Therefore Import-Library is the preferred approach for expressing the dependency on the Spring framework.

[Tip]Tip

How do you determine the name of a library definition provided by the SpringSource dm Server? Use the SpringSource Enterprise Bundle Repository.

Examine the /META-INF/MANIFEST.MF in /dist/formtags-shared-libs-*.war:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.5.0_13-119 (Apple Inc.)
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.springframework.showcase.formtags-shared-libs
Bundle-Vendor: SpringSource Inc.
Import-Library: org.springframework.spring;version="[2.5.4,3.0.0)"
Import-Bundle: com.springsource.org.apache.taglibs.standard;version="1
 .1.2"

You can see the Import-Library and Import-Bundle directives that instruct the dm Server to add the appropriate package imports to the bundle classpath used by this WAR file.

Deploying the shared libraries WAR onto the dm Server should result in console output similar to the following:

[Note]Note

The console output has been reformatted to fit this document.

[2008-05-13 13:23:00.520] fs-watcher
    <SPSC1000I> Creating web application '/formtags-shared-libs-1.0.0.RELEASE'.
[2008-05-13 13:23:00.524] async-delivery-thread-1
    <SPSC1001I> Starting web application '/formtags-shared-libs-1.0.0.RELEASE'.
[2008-05-13 13:23:00.894] fs-watcher
    <SPDE0010I> Deployment of 'formtags-shared-libs-1.0.0.RELEASE.war' version '0' completed.

Navigating to http://localhost:8080/formtags-shared-libs-BUILDTAG should render the welcome page. Note that for the pre-packaged distributable, the BUILDTAG should be similar to 1.0.0.RELEASE; whereas, for a local build the -BUILDTAG may be completely omitted. Please consult the console output, web-based admin console, or log to determine the exact context path under which the web application has been deployed.