4.4 Deploying a bundle
Prev | 4. The Web Module | Next

## 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 Virgo Web Server.

### Deploying the `greenpages.web` bundle and starting the Web Server

The Web Server can be used while working in Eclipse. In this step the `greenpages.web` bundle is deployed and the Web Server instance is started.

Drag the `greenpages.web` project from the Package Explorer and drop it on the Web Server instance in the Servers view. Because `greenpages.web` is a web bundle the server will start automatically, and a browser window may open. Expand the Web Server instance and the bundle `greenpages.web` will be listed as a child.

(Eclipse may open its internal web browser as this is a web project. You can choose to use this or just close it and use another browser later.)

If deployment has gone successfully the console will contain the message `<DE0005I> Started bundle 'greenpages.web' version '2.0.0'.`

Leave the server instance running and go to the next step.

### Creating web module metadata

The Web Server has special knowledge of web application bundles. In this step web bundle 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. If the link is not currently served by any bundle in the Web Server there may be an error displayed:

or else there is a blank page displayed. No pages are served.

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

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

    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 Tools → Run generation of MANIFEST.MF file. This will use a tool called Bundlor (included in STS) 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/webapp` folder.

It should look something like the following:

    Manifest-Version: 1.0
    Bundle-Name: GreenPages Web
    Import-Library: org.springframework.spring;version="[3.0, 3.1)"
    Import-Bundle: com.springsource.org.apache.taglibs.standard;version="[
     1.1.2,1.3)"
    Web-ContextPath: greenpages
    Import-Package: org.eclipse.virgo.server.web.dm;version="[2.0.0, 3.0.0)
     ",freemarker.cache;version="[2.3.15,2.3.15]",javax.servlet.jsp.jstl.c
     ore;version="[1.1.2,1.2.0)",javax.sql,org.apache.commons.dbcp,org.spr
     ingframework.core.io,org.springframework.stereotype,org.springframewo
     rk.web.bind.annotation,org.springframework.web.context,org.springfram
     ework.web.servlet
    Bundle-ManifestVersion: 2
    Bundle-SymbolicName: greenpages.web
    Tool: Bundlor 1.0.0.M6
    Bundle-Version: 2.0

although the order of the entries may be different.

The server (if it is still running) will track these changes and automatically refresh (or restart) the `greenpages.web` bundle as required. Observe the context path for the web bundle being announced (it should now be `'/greenpages'` whereas previously it would have been a default context path derived from the bundle name: `'/greenpages.web'`).

By default, Bundlor generates `Import-Package` entries with no version range specified. In the absence of a version range, the OSGi default (which denotes 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, as in the next step.

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

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

(Again, be careful not to leave trailing spaces on lines or insert blank lines in this file, except that there must be one trailing space after the colon to indicate that the header continues on the next line.)

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 the `springframework` packages:

    Import-Package: org.eclipse.virgo.server.web.dm;version="[2.0.0, 3.0.0)
     ",freemarker.cache;version="[2.3.15,2.3.15]",javax.servlet.jsp.jstl.c
     ore;version="[1.1.2,1.2.0)",javax.sql,org.apache.commons.dbcp,org.spr
     ingframework.core.io;version="[3.0.0, 3.1.0)",org.springframework.ste
     reotype;version="[3.0.0, 3.1.0)",org.springframework.web.bind.annotat
     ion;version="[3.0.0, 3.1.0)",org.springframework.web.context;version=
     "[3.0.0, 3.1.0)",org.springframework.web.servlet;version="[3.0.0, 3.1
     .0)"

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

Put any characters into the entry field and press Submit. This should display a “404” error page with the description:

    description   The requested resource () is not available.

This is because there is no search page (`search.htm`) to process this request yet. The next section will address this.

Prev | Up | Next
4.3 The controller | Home | 4.5 Creating a PAR