2.3 Building and Installing GreenPages

Building with Apache Maven

GreenPages uses Apache Maven as its primary build system. Each bundle 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/ the current directory.

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

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

Installing Dependencies into Virgo Tomcat 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 Virgo Tomcat Server, these dependencies can be loaded into memory as needed, but first they must be made available to Virgo Tomcat 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 Virgo Tomcat Server runtime. These dependencies can then be installed into the Virgo Tomcat Server repository. Dependencies are gathered automatically during the package phase. These dependencies can be found in $GREENPAGES_HOME/greenpages/target/par-provided. To install dependencies simply copy all the *.jar files from this directory into $SERVER_HOME/repository/usr (where $SERVER_HOME is the Virgo Tomcat Server installation directory).

Installing dependencies on Windows:

prompt> cd %GREENPAGES_HOME%\greenpages 
prompt> copy target\par-provided\* %SERVER_HOME%\repoorg.apache.commons.fileuploadsitory\usr

Installing dependencies on UNIX:

prompt$ cd $GREENPAGES_HOME/org.apache.commons.fileuploadgreenpages 
prompt$ cp target/par-provided/* $SERVER_HOME/repository/usr

Notice that Virgo Tomcat 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 Virgo Tomcat Server when copying these files. The next time Virgo Tomcat Server is started the -clean option will cause Virgo Tomcat Server to re-scan the repository directories in any case. It is always safe to start Virgo Tomcat Server with the -clean option.

Starting and Configuring the Database

GreenPages uses the H2 database to store all its data. Before starting the application, 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

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 Virgo Tomcat Server and start it:

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

    prompt$ cd $SERVER_HOME
    prompt$ cp $GREENPAGES_HOME/greenpages/target/greenpages-2.5.0.RELEASE.par pickup/

    On Windows:

    prompt> cd %SERVER_HOME%
    prompt> copy %GREENPAGES_HOME%\greenpages\target\greenpages-2.5.0.RELEASE.par pickup\
  2. Start Virgo Tomcat Server with the -clean option. On Unix:

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

    On Windows:

    prompt> "%SERVER_HOME%"\bin\startup.bat -clean
  3. Verify that GreenPages starts correctly by checking in the Virgo Tomcat Server output for the log message:

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