4.5 Creating a PAR
Prev | 4. The Web Module | Next

## 4.5 Creating a PAR

At the end of the previous step, the Web Server instance was started and the `greenpages.web` bundle deployed. This bundle shows a static home page but a search value causes an error. The error appears because the URL for that search is not serviced by the controller. The application logic behind the search request is not in the `greenpages.web` project but in another project called `greenpages.app`. This section creates the `greenpages.app` project and then combines the two projects into a PAR so as to deploy them together as a single unit.

While executing these instructions it is not necessary to remove bundles from the Web Server instance, nor to stop the instance. As changes are made the bundle will be refreshed (or redeployed) and the server instance may report errors if the changes are incomplete. These may safely be ignored. Alternatively, the `greenpages.web` bundle can be removed from the Web Server instance, or the server can be stopped while these changes are made.

### Importing the parent project

All of the bundles in the GreenPages sample are Maven projects which refer to a ‘parent’ project. To allow STS to accommodate references to the parent, import this project first.

In the same way that the starting `greenpages.web` project was imported (see Section 4.3, “The controller”) import the `$GREENPAGES_HOME/start/parent` project.

### Importing the `greenpages.app` project

In this step, the `greenpages.app` project is imported which contains the business interfaces (and stub implementations of these interfaces).

In the same way that the starting `greenpages.web` project was imported (see Section 4.3, “The controller”) import the `$GREENPAGES_HOME/start/greenpages.app` project.

When Eclipse finishes importing the project, go to the next step.

### Adding the controller implementation

The controller implementation will depend on the `Directory` and `Listing` interfaces found in the `greenpages.app` project. In this step, the implementation is added.

Open the `GreenPagesController` class. Add the following field and methods to the class:

    @Autowired
    private Directory directory;

    @RequestMapping("/search.htm")
    public List<Listing> search(@RequestParam("query") String query) {
      return this.directory.search(query);
    }

    @RequestMapping("/entry.htm")
    public Listing entry(@RequestParam("id") int id) {
      return this.directory.findListing(id);
    }

Add the (Quick Fix) suggested imports for the annotations `Autowired` and `RequestParam`, and choose the import for `List< >` from `java.util.List`.

Eclipse will not be able to suggest import statements for the `Listing` and `Directory` types. This is because the `greenpages.web` and `greenpages.app` projects are not linked together and therefore cannot see each other’s types.

Proceed to the next step.

### Creating a PAR project

In Web Server, applications consisting of multiple bundles can be packaged as part of a PAR. In this step a PAR project containing the `greenpages.web` and `greenpages.app` bundles is created and deployed to the server.

Right-click in the Package Explorer and select New → Project???. In the dialog that opens select EclipseRT → PAR Project and press Next:

In the New PAR Project dialog, ensure the Use default location option is unchecked, name the project `greenpages`, set the location to `$GREENPAGES_HOME/start/greenpages` and press Next.

In the next dialog, some of the PAR properties are pre-populated. Change the Application Name to `Greenpages PAR` and the Version to `2.3.0`, then ensure that the Target Runtime is set to Virgo Web Server (Runtime) v2.1 and press Next.

In the next dialog, select the `greenpages.app` and `greenpages.web` bundles so that they are contained in the PAR and press Finish.

The project `greenpages.web` still shows errors; these are soon to be fixed.

The package explorer view will now show the following:

PAR project creation is complete, go to the next section.

Prev | Up | Next
4.4 Deploying a bundle | Home | 4.6 Referencing an OSGi Service