4.5 Creating a PAR

At the end of the previous step, the dm Server instance was started and the greenpages.web bundle deployed. This bundle shows a static home page but a search value causes an error. This error appears because the URL for that search was not serviced by the controller. The 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 be able to deploy them together as a single unit.

While executing these instructions it is not necessary to remove bundles from the dm 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 dm Server instance, or the server can be stopped while these changes are made.

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 (in section the section called “Importing the greenpages.web project”) 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 dm 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 NewProject…. In the dialog that opens select SpringSource dm ServerPAR 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. Ensure that the Target Runtime is set to SpringSource dm Server (Runtime) 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.

greenpages.web still has 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.