4.4 Deploying a bundle

During development time, it can be helpful to run an application inside of the deployment container. In the case of Greenpages, this means deploying the greenpages.web bundle to the SpringSource dm Server.

Deploying the greenpages.web bundle and starting the dm Server

The dm Server can be used while inside of Eclipse. In this step you will deploy the greenpages.web bundle and start the dm Server instance.

Drag the greenpages.web project from the Package Explorer and drop it on the dm Server instance in the Servers view. Expand the dm Server instance and the bundle will be shown as a child of the dm Server.

Right-click on the dm Server instance and select Start. If deployment has gone successfully the console will print <SPDE0010I> Deployment of 'greenpages.web' version '1' completed.

(If the server fails to start, re-check that the modifications to server.config were entered correctly in section the section called “Setting up dm Server”.)

When this message is displayed, leave the server instance running and go to the next step.

Creating web module metadata

The dm Server has special knowledge of the web application bundles. In this step web module metadata is added to the bundle and a web browser is used to navigate to it.

Open a web browser and navigate to http://localhost:8080/greenpages/home.htm. The link is not currently served by any bundle in the dm Server so there will be an error displayed:

To fix this issue the greenpages.web bundle must be declared to be a web module and a context path can be defined.

Open the template.mf file (at the top level under the greenpages.web project) and add (and save) the following entries (using the template.mf pane of the editor):

Module-Type: web
Web-ContextPath: greenpages

Be careful not to insert any blank lines or trailing spaces in this file.

Once added, right-click on the greenpages.web project and select Spring ToolsRun automatic generation of MANIFEST.MF file. This will use a tool called Bundlor to update the OSGi metadata in the MANIFEST.MF file. Once Bundlor has finished running, open the META-INF/MANIFEST.MF file in the src/main/resources source folder. It should look like the following:

Manifest-Version: 1.0
Bundle-Name: GreenPages Web
Bundle-Classpath: .
Web-ContextPath: greenpages
Import-Package: org.springframework.stereotype,org.springframework.web
 .bind.annotation,org.springframework.web.servlet.mvc.annotation,org.s
 pringframework.web.servlet.view.freemarker
Bundle-ManifestVersion: 2
Bundle-Vendor: SpringSource Inc.
Module-Type: web
Bundle-SymbolicName: greenpages.web
Export-Package: greenpages.web;version="1.0";uses:="org.springframewor
 k.stereotype,org.springframework.web.bind.annotation"
Bundle-Version: 1.0

By default, Bundlor generates Import-Package entries with no version range specified. In the absence of a version range, the OSGi default (of any version) is used. While this is very flexible it is generally a good idea to restrict an import by specifying a narrower range. This can be achieved by providing Bundlor with some additional information in the manifest template.

Add and save the following entry to the template.mf file:

Import-Template: 
 org.springframework.*;version="[2.5.6.A, 3.0.0)"

(Again, be careful not to leave trailing spaces on lines or insert blank lines in this file.)

Re-run the MANIFEST.MF generation as described earlier. In the MANIFEST.MF file the Import-Package entry should now have version ranges on each of its packages:

Import-Package: org.springframework.stereotype;version="[2.5.6.A, 3.0.
 0)",org.springframework.web.bind.annotation;version="[2.5.6.A, 3.0.0)
 ",org.springframework.web.servlet.mvc.annotation;version="[2.5.6.A, 3
 .0.0)",org.springframework.web.servlet.view.freemarker;version="[2.5.
 6.A, 3.0.0)"

Behind the scenes the dm Server Tools have refreshed the deployed bundle as changes were made. Once again navigate to http://localhost:8080/greenpages/home.htm. This page now displays an entry field.

Put any characters into the entry field and press Submit. This should display a “404” page again, similar to before. This is because there is no search page (search.htm) to process this request yet. The next section will address this.