3.3 Building and installing GreenPages
Prev | 3. Installing and exploring GreenPages | Next

## 3.3 Building and installing GreenPages

### Building with Apache Maven

GreenPages uses Apache Maven as its primary build system. Each module of the application can be built separately and the entire application can built and assembled into a PAR file from a single location. To build the application and assemble it into a PAR file:

1. Make `$GREENPAGES_HOME/solution` the current directory.

2. Run the command `mvn package`. The first time this is run several files will be downloaded from Maven repositories and SpringSource repositories. Subsequent runs will not need to do this.

3. Verify that the `greenpages-2.1.0.RELEASE.par` file exists in `$GREENPAGES_HOME/solution/greenpages/target`.

### Installing dependencies into Web Server

Unlike traditional Java EE applications, GreenPages does not package all of its dependencies inside its deployment unit. Instead, it relies on the mechanisms of OSGi to locate its dependencies at runtime. When running an OSGi application on Web Server, these dependencies can be loaded into memory as needed, but first they must be made available to Web Server.

The Maven build included with GreenPages uses the `dependency:copy-dependencies` plugin to gather all the artifacts that GreenPages depends on that are not supplied by the Web Server runtime. These dependencies can then be installed into the Web Server repository. Dependencies are gathered automatically during the `package` phase. These dependencies can be found in `$GREENPAGES_HOME/solution/greenpages/target/par-provided`. To install dependencies simply copy all the `*.jar` files from this directory into `$VWS_HOME/repository/usr`.

Installing dependencies on Windows:

    prompt> cd %GREENPAGES_HOME%\solution\greenpages
    prompt> copy target\par-provided\* %VWS_HOME%\repository\usr

Installing Dependencies on UNIX:

    prompt$ cd $GREENPAGES_HOME/solution/greenpages
    prompt$ cp target/par-provided/* $VWS_HOME/repository/usr

Notice that Web Server will not necessarily see these dependencies unless its repository indexes are rebuilt. Different repositories behave differently in this respect; some are passive (their indexes are built only once upon startup) and some are active (they can detect new files or files being removed dynamically). The `usr` repository is active so there is no need to restart Web Server when copying these files. The next time Web Server is started the `-clean` option will cause Web Server to re-scan the repository directories in any case. It is always safe to start Web Server with the `-clean` option.

### Starting and configuring the database

GreenPages uses the H2 database to store all its data. Before you can start the application, you must start the database server and populate the database with data.

1. Change to the `$GREENPAGES_HOME/db` current directory. On Unix:

       prompt$ cd $GREENPAGES_HOME/db

   On Windows:

       prompt> cd %GREENPAGES_HOME%\db

2. Run the database startup script appropriate to the operating system. For Unix, this is `run.sh`, run in the background:

       prompt$ sh run.sh &

   Press Return to continue.

   On Windows, run the `run.bat` command:

       prompt> run

   For both platforms, the command might invoke a browser window offering a connection to the database; close this window.

3. Run the data population script appropriate to the operating system. For Unix, this is `data.sh`:

       prompt$ sh data.sh

   On Windows, run the `data.bat` command:

       prompt> data

You only to need run these commands once to start a database server for H2; the server will continue to run in the background.

### Installing and starting GreenPages PAR

To install the GreenPages PAR into Web Server and start it:

1. Copy the GreenPages PAR to the `$VWS_HOME/pickup` directory. On Unix:

       prompt$ cd $VWS_HOME
       prompt$ cp $GREENPAGES_HOME/solution/greenpages/target/greenpages-solution-2.1.0.RELEASE.par pickup/

   On Windows:

       prompt> cd %VWS_HOME%
       prompt> copy %GREENPAGES_HOME%\solution\greenpages\target\greenpages-solution-2.1.0.RELEASE.par pickup\

2. Start Web Server with the `-clean` option. On Unix:

       prompt$ $VWS_HOME/bin/startup.sh -clean

   On Windows:

       prompt> "%VWS_HOME%"\bin\startup.bat -clean

3. Verify that GreenPages starts correctly by checking in the Web Server output for the log message:

       <DE0005I> Started par 'greenpages' version '2.1.0.RELEASE'.

Prev | Up | Next
3.2 Obtaining GreenPages | Home | 3.4 Browsing the GreenPages application