Groovy with Maven Quick Start

Modified: 01/26/2008, Created: 11/13/2007

A Groovy based Maven project can come in at least two different packaging/artifact types: groovy-jar and war . For more information about groovy-jar packaging, see http://mojo.codehaus.org/groovy/groovy-maven-plugin/mixed-compilation.html This document contains two sets of quick start instructions depending on the packaging/archive type the Maven project is to build:

  • Option A: Creating a new groovy-jar Package Groovy-based Module Maven Project (Non-web)
  • Option B: Creating a new war Package Groovy-based Module Maven Project (Web)
    • Bonus: Add Some Ajax Examples with GSP as the Server-side

Option A: Creating a new groovy-jar Package Groovy-based Module Maven Project

Option A describes the steps to get a Maven built Groovy-based non-web project created.

  • Here is the command pattern to create a Groovy based project, groovy-jar artifact project. Don't issue this command as I will run this command with different values in the step below
    mvn archetype:create \
        -DarchetypeGroupId=org.codehaus.mojo.groovy \
        -DarchetypeArtifactId=groovy-maven-archetype \
        -DgroupId=com.mycompany.app \
        -DpackageName=com.mycompany.app.mygroovymodule \
        -DartifactId=my-groovy-module
    
    • Here are the specific values that we will use to create a Groovy based groovy-jar artifact project.
      mvn archetype:create -DarchetypeGroupId=org.codehaus.mojo.groovy -DarchetypeArtifactId=groovy-maven-archetype -DgroupId=com.mycompany.app -DpackageName=com.mycompany.app.mygroovymodule -DartifactId=my-groovy-module
      
  • The above mvn archetype:create command created the directory my-groovy-module and multiple files and directories under it.
  • Change directory into folder my-groovy-module
    cd my-groovy-module
    
  • Notice that the groovy-maven-archetype archetype:create created the following files and directories:
    • pom.xml
    • src/main/java/com/mycompany/app/mygroovymodule/MyExampleClass.groovy
    • src/main/java/com/mycompany/app/mygroovymodule/MySupportClass.java
    • src/site/site.xml
    • src/site/apt/index.apt

      Also notice that the pom.xml file generated contains the line "<packaging>groovy-jar</packaging>"

          <groupId>com.mycompany.app</groupId>
          <artifactId>my-groovy-module</artifactId>
          <name>Example Groovy Module - my-groovy-module</name>
          <packaging>groovy-jar</packaging>
          <version>1.0-SNAPSHOT</version>
      

    Also notice that there is not a <dependency> tag with groovy-all .

  • In pom.xml, I went ahead and commented out the line "<defaultGoal>install</defaultGoal>"
    ...
       <build>
          <!--
          <defaultGoal>install</defaultGoal>
          -->
    ...
    
  • (01/22/2008) If you were to attempt to build the project by issuing the command:
    mvn package
    

    as it is now, you will get an error message similar to the following:

    [INFO] FileSet <directory> does not exist: C:\_dev\projects\my-groovy-module\src\main\groovy
    
    • The groovy-maven-plugin requires the following two folders to exist even if they have no contents.
      • src/test/groovy
      • src/main/groovy
    • You will need to create the two folders. I guess this is a bug in the archetype.
      • If you are on Windows OS, you could issue the following commands to accomplish this.
        mkdir src\main\groovy
        mkdir src\test\groovy
        
  • You can now build the the project by issuing the command:
    mvn package
    
  • Optionally, to create Eclipse IDE project files in order to import the project into Eclipse IDE, run the command
    mvn eclipse:clean eclipse:eclipse
    
    • If you are using Eclipse IDE, you can now import this project into your Eclipse IDE workspace.
    • TIP: In Eclipse IDE (unless you have the Groovy Eclipse plug-in installed) (for the first time), right click on *.groovy files and select Open With > Text Editor to edit them.
  • It appears to the author that the sample Groovy and Java source code created by the groovy-maven-archetype archetype:create are in the wrong location to show off the Groovy Maven plugin; so, to fix this,

    move the file

    • src/main/java /com/mycompany/app/mygroovymodule/MyExampleClass.groovy

    to

    • src/main/groovy /com/mycompany/app/mygroovymodule/MyExampleClass.groovy

    Also move the file

    • src/main/java /com/mycompany/app/mygroovymodule/MySupportClass.java

    to

    • src/main/groovy /com/mycompany/app/mygroovymodule/MySupportClass.java
  • The groovy-maven-plugin allows for the following conventions:
    • Any Groovy (or java code) under src/main/groovy will be compiled into *.class files at the folder target/classes
    • Any Groovy tests under src/test/groovy will be compiled into *.class files at the folder target/test-classes
    • If you want your *.groovy files to stay uncompiled, place them in src/main/resources . Groovy files residing in src/main/resources will show up in the artifact file uncompiled.
    • If you encounter compile problems with Groovy files that contain
      static void main(String[] args)
      {
      ...
      

    , change the function to be

    static void main(args)
    {
    ...
    
  • (11/07/2007) Optionally to see how Groovy Unit Tests are handled, do the following. For the Groovy project above, Copy, rename and edit the following file
    • src/main/groovy/com/mycompany/app/mygroovymodule/MyExampleClass.groovy

    to become

    • src/test/groovy/com/mycompany/app/mygroovymodule/MyExampleClassTest.groovy

    And copy, rename and edit the following file

    • src/main/groovy/com/mycompany/app/mygroovymodule/MySupportClass.java

    to become

    • src/test/groovy/com/mycompany/app/mygroovymodule/MySupportClassTest.java
  • Now, Maven will run unit tests located in src/test/java or src/test/groovy when the project is built. Groovy unit tests not located in src/test/groovy will not be executed.
    • To build and run unit tests, run the command
      mvn package
      
    • To clean then build and run unit tests, run the command
      mvn clean package
      
  • Optionally, if you need the dependency lib files to be available after the build, add the following section to the pom.xml file within your <build><plugins> tag
    <build>
    ...
            <plugins>
    ...
                    <!-- this plugin will copy the dependencies to 
                    a "lib" folder during the package phase -->
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <executions>
                                    <execution>
                                            <id>copy-dependencies</id>
                                            <phase>package</phase>
                                            <goals>
                                                    <goal>copy-dependencies</goal>
                                            </goals>
                                            <configuration>
                                                    <!-- configure the plugin here -->
                                                    <excludeScope>provided</excludeScope>
                                                    <includeTypes>jar</includeTypes>
                                                    <excludeTypes>war</excludeTypes>
                                                    <overWrite>true</overWrite>
                                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                            </configuration>
                                    </execution>
                            </executions>
                    </plugin>
    ...
            </plugins>
    ...
    </build>
    

    Now, you will get the dependency jar files deposited in target/lib when you issue the command:

    mvn package
    
  • Optionally, if you wanted to specify a dependency on other library jar files such as Spring or Groovy, you could add the following section to the pom.xml file.
    <properties>
            <spring.version>2.5.1</spring.version>
    </properties>
    
    <dependencies>
            <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                    <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>1.5.1</version>
            </dependency>
    
    
            <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.14</version>
                    <scope>compile</scope>
            </dependency> 
    
            <dependency>
                    <groupId>commons-lang</groupId>
                    <artifactId>commons-lang</artifactId>
                    <version>2.3</version>
                    <scope>compile</scope>
            </dependency>
    
            <dependency>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                    <!--<version>[1.1,)</version>-->
                    <version>1.1</version>
                    <scope>compile</scope>
                    <exclusions>
                <exclusion>
                   <groupId>log4j</groupId>
                   <artifactId>log4j</artifactId>
                </exclusion>
                <exclusion>
                   <groupId>logkit</groupId>
                   <artifactId>logkit</artifactId>
                </exclusion>
                <exclusion>
                   <groupId>avalon-framework</groupId>
                   <artifactId>avalon-framework</artifactId>
                </exclusion>
                <exclusion>
                   <groupId>javax.servlet</groupId>
                   <artifactId>servlet-api</artifactId>
                </exclusion>
                    </exclusions>
            </dependency>
    
    </dependencies>
    ...
    
    • If you changed added the dependencies in this step, you will want to recreate the Eclipse IDE project files.
      mvn eclipse:clean eclipse:eclipse
      
  • Optionally, if you would like your module to compile using the latest version of Java (version 1.6 a.k.a. 6.0), add the following section to the pom.xml file within your <build><plugins> tag
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                            <encoding>UTF-8</encoding>
                            </configuration>
                    </plugin>
    
  • Optionally, if you would like your module to have the source code available to your Eclipse IDE project, add the following section to the pom.xml file within your <build><plugins> tag
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-eclipse-plugin</artifactId>
                            <configuration>
                                    <downloadSources>true</downloadSources>
                                    <downloadJavadocs>true</downloadJavadocs>
                            </configuration>
                    </plugin>
    
    • If you added the above section to your pom.xml, you will want to recreate the Eclipse IDE project files.
      mvn eclipse:clean eclipse:eclipse
      

Executing a Class in Your Project

  • If you are using Java 6, you can run a Java class with the following command:
    java -cp "target/classes;target/lib/*" com.mycompany.app.MyExampleClass
    
    • If you are using Java 5 or previous, you can run a Java class with the following command:
      java -cp "target/classes;target/lib/nameoflib1.jar;target/lib/nameoflib2.jar" com.mycompany.app.MyExampleClass
      

      Replace nameoflib# with names of jar files your are dependent upon.

  • To run an uncompiled Groovy script, issue a command similar to
    groovy -cp "target/classes;target/lib/nameoflib1.jar;target/lib/nameoflib2.jar" target/classes/path/to/script/GroovyScriptFileName
    

Option B: Creating a new war Package Groovy-based Module Maven Project

Option B describes the steps to get a Maven built Groovy-based web project created.

The above steps are satisfactory if the project artifact is a jar file, but we may want to code with Groovy in a Web Application resulting in a war artifact.

I will assume you will run the web application with Tomcat 6 and already have it installed and working correctly.

  • Here is the command pattern to create a Web Application based project, war artifact project. Don't issue this command as I will run this command with different values in the step below.
    mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
    
    • Here are the specific values that I used to Create a Web Application, war artifact project.
      mvn archetype:create -DgroupId=com.mycompany.webapp -DpackageName=com.mycompany.webapp.mygroovywebmodule -DartifactId=my-groovy-web-module -DarchetypeArtifactId=maven-archetype-webapp
      
  • Change directory into folder my-groovy-web-module
    cd my-groovy-web-module
    
  • Add the following to your pom.xml file if not already present.
    <?xml version="1.0"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
    ...     
    
    <packaging>war</packaging>
    
    ...     
    
    <dependencies>
    ...     
            <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>1.5.1</version>
            </dependency>
    ...     
    </dependencies>
    
    <build>
    ...     
            <plugins>
    ...     
                    <!-- maven groovy plugin, 
                    any *.groovy files in src/main/groovy or src/test/groovy
                    will be compiled to *.class files
                    -->
                    <plugin>
                            <groupId>org.codehaus.mojo.groovy</groupId>
                            <artifactId>groovy-maven-plugin</artifactId>
                            <version>1.0-beta-2</version>
                            <!--<extensions>true</extensions>-->
                            <executions>
                                    <execution>
                                            <goals>
                                                    <goal>generateStubs</goal>
                                                    <goal>compile</goal>
                                                    <goal>generateTestStubs</goal>
                                                    <goal>testCompile</goal>
                                            </goals>
                                    </execution>
                            </executions>
                    </plugin>
    
                    <!-- Jetty plugin to run app from Maven -->
                    <plugin> 
                            <groupId>org.mortbay.jetty</groupId>
                            <artifactId>maven-jetty-plugin</artifactId>
                    </plugin> 
    
                    <!-- Configure surefire to ignore integration tests on "test" and
                    to ignore plain unit-tests on "integration-test" -->
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                    <excludes>
                                            <!--<exclude>**/*ITest.java</exclude>-->
                                            <exclude>**/*ITest.*</exclude>
                                    </excludes>
                            </configuration>
                            <executions>
                                    <execution>
                                            <id>integration tests</id>
                                            <phase>integration-test</phase>
                                            <goals><goal>test</goal></goals>
                                            <configuration>
                                                    <includes>
                                                            <!--<include>**/itest/*ITest.java</include>-->
                                                            <include>**/itest/*ITest.*</include>
                                                    </includes>
                                                    <excludes>
                                                            <exclude>none</exclude>
                                                    </excludes>
                                            </configuration>
                                    </execution>
                            </executions>
                    </plugin>
    
                    <!-- Start Jetty on pre-integration-test and shut it down on post-integration-test -->
                    <plugin>
                            <groupId>org.codehaus.cargo</groupId>
                            <artifactId>cargo-maven2-plugin</artifactId>
                            <executions>
                                    <execution>
                                            <id>start-container</id>
                                            <phase>pre-integration-test</phase>
                                            <goals>
                                                    <goal>start</goal>
                                            </goals>
                                            <configuration>
                                            <wait>false</wait>
                                            </configuration>
                                    </execution>
                                    <execution>
                                            <id>stop-container</id>
                                            <phase>post-integration-test</phase>
                                            <goals>
                                                    <goal>stop</goal>
                                            </goals>
                                    </execution>
                            </executions>
                            <configuration>
                                    <container>
                                            <systemProperties>
                                                    <org.apache.commons.logging.Log>org.apache.commons.logging.impl.SimpleLog</org.apache.commons.logging.Log>
                                            </systemProperties> 
                                    </container>
                            </configuration>
                    </plugin>
    ...
            </plugins>
    
            <resources>
    ...     
                    <resource>
                            <!-- maven default
                            When sources is specified 
                            the default location is not automatically included
                            -->
                            <directory>src/main/resources</directory>
                    </resource>
                    <!-- needed to copy over the *.groovy files into the WEB-INF/classes dir -->
                    <resource>
                            <directory>src/main/java</directory>
                            <includes>
                                    <include>**/*.groovy</include>
                            </includes>
                    </resource>
    ...     
            </resources>  
    
    
    </build>
    
    <reporting>
            <plugins>
    ...     
                    <plugin>
                            <groupId>org.codehaus.mojo.groovy</groupId>
                            <artifactId>groovy-maven-plugin</artifactId>
                            <!--
                            <version>1.0-beta-2</version>
                            -->
                    </plugin>
    ...     
            </plugins>
    </reporting>
    
    ...
    
    </project>
    
    
  • You will then need to create the following two folders. The groovy-maven-plugin requires these two folders to exist even if they have no contents.
    src/test/groovy
    src/main/groovy
    
    • If you are on Windows OS, you could issue the following commands to accomplish this.
      mkdir src\main\groovy
      mkdir src\test\groovy
      
  • To create Eclipse IDE project files in order to import the project into Eclipse IDE, run the command
    mvn eclipse:clean eclipse:eclipse
    
    • TIP: In Eclipse IDE (unless you have the Groovy Eclipse plug-in installed) (for the first time), right click on *.groovy or *.gsp files and select Open With > Text Editor to edit them.
  • Optionally, if you would like your module to compile using the latest version of Java (version 1.6 a.k.a. 6.0), add the following section to the pom.xml file within your <build><plugins> tag
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                            <encoding>UTF-8</encoding>
                            </configuration>
                    </plugin>
    
  • Optionally, if you would like your module to have the source code available to your Eclipse IDE project, add the following section to the pom.xml file within your <build><plugins> tag
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-eclipse-plugin</artifactId>
                            <configuration>
                                    <downloadSources>true</downloadSources>
                                    <downloadJavadocs>true</downloadJavadocs>
                            </configuration>
                    </plugin>
    
    • If you added the above section to your pom.xml, you will want to recreate the Eclipse IDE project files.
      mvn eclipse:clean eclipse:eclipse
      
  • The groovy-maven-plugin allows for the following convention
    • Any Groovy tests under src/test/groovy will be compiled into *.class files at the folder target/test-classes
    • Any Groovy (or java code) under src/main/groovy will be compiled into *.class files at the folder target/classes
  • If you want your *.groovy files to stay uncompiled, place them in src/main/resources . Groovy files residing in src/main/resources will show up in the artifact file uncompiled.
  • You can now add Groovy and Java Unit and Integration tests named with the following conventions:
    Test Type File Name Pattern folder
    Unit Tests coded in Java **/*Test.java src/test/java
    Unit Tests coded in Groovy **/*Test.groovy src/test/groovy
    Integration Tests coded in Java **/itest/*ITest.java src/test/java
    Integration Tests coded in Groovy **/itest/*ITest.groovy src/test/groovy

    You can change this pattern by configuring the naming pattern in the maven-surefire-plugin configuration in the pom.xml file.

  • Maven automatically will run the unit tests when you build the project. Such as with the following command
    mvn package
    
  • Maven will automatically run the integration tests (including running Jetty) when one runs the command:
    mvn integration-test
    
  • If you are using Tomcat, edit the file <YOUR_TOMCAT_INSTALL_DIR>/conf/server.xml and add between the <Host> (near the end)
    <Context path="/my-groovy-web-module" 
             debug="5" 
             reloadable="true" 
             docBase="C:\dev\projects\my-groovy-web-module\target\my-groovy-web-module"/>
    

    Change the value of docBase to be the location of your project.

Adding Groovy Code Samples

  • At this point, all you have is a web application with an index.jsp page and no Groovy code. So, lets begin to add some Groovlet and GSP (GroovyServer Pages) sample files.
  • To enable GSP and Groovlet files, edit the web.xml file to be similar to the following listing
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       version="2.5"> 
    
    <description>
    A Groovy Based Web Application
    </description>
    <display-name>Archetype Created Web Application</display-name>
    
    <servlet>
            <servlet-name>GroovyServlet</servlet-name>
            <servlet-class>groovy.servlet.GroovyServlet</servlet-class>
    </servlet>
    <servlet>
            <servlet-name>GroovyTemplateServlet</servlet-name>
            <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
            <init-param>
                    <param-name>generated.by</param-name>
                    <param-value>false</param-value>
            </init-param>
    <!--
            <init-param>
                    <param-name>encoding</param-name>
                    <param-value>ISO-8859-1</param-value>
            </init-param>
            <init-param>
                    <param-name>debug</param-name>
                    <param-value>0</param-value>
            </init-param>
    -->
    </servlet>
    
    <servlet-mapping>
            <servlet-name>GroovyServlet</servlet-name>
            <url-pattern>*.groovy</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
            <servlet-name>GroovyTemplateServlet</servlet-name>
            <url-pattern>*.gsp</url-pattern>
    </servlet-mapping>
    
    </web-app>
    
  • The init param generated.by prevents the following message from appearing in your GSP pages, which could mess up Ajax clients not expecting it.
    <!-- Generated by Groovy TemplateServlet [create/get=0 ms, make=2 ms] -->
    
  • Here are some sample GSP and Groovlets for you to add to the project.

    The inspiration for some of the sample code is from the following links

file add to project location Note
diagnostic.groovy
example1.groovy
helloworld.gsp
helloworld.gsp
randcolor.gsp
simple.gsp
AGroovyScript.groovy
AGroovyScript2.groovy
src/main/webapp
src/main/webapp
src/main/webapp
src/main/webapp/gsp/dir
src/main/webapp
src/main/webapp
src/main/groovy
src/main/resources
  • To build (package into a war file) and run unit tests, run the command
    mvn package
    
  • To clean then build (package into a war file) and run unit tests, run the command
    mvn clean package
    
  • On a side note. Maven will run unit tests located in src/test/java or src/test/groovy when the project is built. Groovy unit tests not located in src/test/groovy will not be executed.
  • To start Tomcat, issue the following command while in the directory <YOUR_TOMCAT_INSTALL_DIR>\bin
    startup
    
  • Here are some URLs you can try out in a web browser:
    http://localhost:8080/my-groovy-web-module/
    http://localhost:8080/my-groovy-web-module/helloworld.gsp
    http://localhost:8080/my-groovy-web-module/simple.gsp
    http://localhost:8080/my-groovy-web-module/randcolor.gsp
    
    http://localhost:8080/my-groovy-web-module/diagnostic.groovy
    http://localhost:8080/my-groovy-web-module/example1.groovy
    
  • To stop Tomcat, issue the following command while in the directory <YOUR_TOMCAT_INSTALL_DIR>\bin
    shutdown
    

Bonus: Add Some Ajax Examples with GSP as the Server-side

  • This section on Ajax can be a continuation of the above section on getting a Maven web project that is Groovy ready.
    • However, I created a new project with an artifactId of groovyajax instead of my-groovy-web-module. Thus I used the Maven archetype:create command:
      mvn archetype:create -DgroupId=com.mycompany.webapp -DpackageName=com.mycompany.webapp.groovyajax -DartifactId=groovyajax -DarchetypeArtifactId=maven-archetype-webapp
      

    and then followed the above "Option B: Creating a new war Package Groovy-based Module Maven Project" steps to get to here.

    • This project was configured in Tomcat's <YOUR_TOMCAT_INSTALL_DIR>/conf/server.xml file with the following
      <Context path="/groovyajax" 
               debug="5" 
               reloadable="true" 
               docBase="C:\dev\projects\groovyajax\target\groovyajax"/>
      

    Change the value of docBase to be the location of your project.

  • The basis for the Ajax samples are the source code files available from the "Head Rush Ajax" book ( http://www.headfirstlabs.com/books/hrajax/ ) The examples in "Head Rush Ajax" have server side code written in PHP. This guide provides GSP code replacements for the PHP code. Other files are updated to call the GSP instead of PHP.

    To get the "Head Rush Ajax" examples to work:

    • download the "Head Rush Ajax" book source code from http://www.headfirstlabs.com/books/hrajax/
    • extract the chapter folders from the zip files
    • place the extracted chapter folders in your project at src/main/webapp .
  • The following are the modified files you should place over the files placed in the previous step.
    file add to project location Note
    boards.html
    getUpdatedBoardSales-ajax.gsp
    boards.html
    getUpdatedBoardSales-ajax.gsp
    lookupCustomer.gsp
    pizza.html
    placeOrder.gsp
    lookupCustomer.gsp
    pizza.html
    placeOrder.gsp
    coffee-sync.js
    coffee.js
    coffeemaker.gsp
    lookupCustomer.gsp
    pizza.js
    placeOrder.gsp
    lookupCustomer.gsp
    pizza.js
    placeOrder.gsp
    boards.js
    getUpdatedSales.gsp
    boards.js
    getUpdatedSales.gsp
    src/main/webapp/chapter01/boards-complete/
    src/main/webapp/chapter01/boards-complete/
    src/main/webapp/chapter02/boards-complete/
    src/main/webapp/chapter02/boards-complete/
    src/main/webapp/chapter02/breakneck-complete/
    src/main/webapp/chapter02/breakneck-complete/
    src/main/webapp/chapter02/breakneck-complete/
    src/main/webapp/chapter02-interlude/breakneck-complete/
    src/main/webapp/chapter02-interlude/breakneck-complete/
    src/main/webapp/chapter02-interlude/breakneck-complete/
    src/main/webapp/chapter03/coffee-complete/
    src/main/webapp/chapter03/coffee-complete/
    src/main/webapp/chapter03/coffee-complete/
    src/main/webapp/chapter05/breakneck-complete/
    src/main/webapp/chapter05/breakneck-complete/
    src/main/webapp/chapter05/breakneck-complete/
    src/main/webapp/chapter05-interlude/breakneck-complete/
    src/main/webapp/chapter05-interlude/breakneck-complete/
    src/main/webapp/chapter05-interlude/breakneck-complete/
    src/main/webapp/chapter06/boards-complete/
    src/main/webapp/chapter06/boards-complete/
    src/main/webapp/chapter07/boards/
    src/main/webapp/chapter07/boards/
  • To build (package into a war file) and run unit tests, run the command
    mvn package
    
    • To clean then build (package into a war file) and run unit tests, run the command
      mvn clean package
      
  • On a side note. Maven will run unit tests located in src/test/java or src/test/groovy when the project is built. Groovy unit tests not located in src/test/groovy will not be executed.
  • To start Tomcat, issue the following command while in the directory <YOUR_TOMCAT_INSTALL_DIR>\bin
    startup
    
  • Here are some URLs you can try out in a web browser:
    http://localhost:8080/groovyajax/chapter01/boards-complete/getUpdatedBoardSales-ajax.gsp
    http://localhost:8080/groovyajax/chapter01/boards-complete/boards.html
    
    http://localhost:8080/groovyajax/chapter02/boards-complete/getUpdatedBoardSales-ajax.gsp
    http://localhost:8080/groovyajax/chapter02/boards-complete/boards.html
    
    http://localhost:8080/groovyajax/chapter02/breakneck-complete/lookupCustomer.gsp
    http://localhost:8080/groovyajax/chapter02/breakneck-complete/pizza.html
    
    http://localhost:8080/groovyajax/chapter02-interlude/breakneck-complete/lookupCustomer.gsp
    http://localhost:8080/groovyajax/chapter02-interlude/breakneck-complete/pizza.html
    
    http://localhost:8080/groovyajax/chapter03/coffee-complete/coffee-sync.html
    http://localhost:8080/groovyajax/chapter03/coffee-complete/coffee.html
    
    http://localhost:8080/groovyajax/chapter03/coffee-complete/coffeemaker.gsp
    
    http://localhost:8080/groovyajax/chapter04/simple.html
    http://localhost:8080/groovyajax/chapter04/whatAmI.html
    http://localhost:8080/groovyajax/chapter04/tree-test.html
    http://localhost:8080/groovyajax/chapter04/top5-complete/top5.html
    
    http://localhost:8080/groovyajax/chapter05/breakneck-complete/pizza.html
    
    http://localhost:8080/groovyajax/chapter05-interlude/breakneck-complete/pizza.html
    
    http://localhost:8080/groovyajax/chapter06/boards-complete/getUpdatedSales.gsp
    http://localhost:8080/groovyajax/chapter06/boards-complete/boards.html
    
    http://localhost:8080/groovyajax/chapter07/boards/boards.html
    
  • To stop Tomcat, issue the following command while in the directory <YOUR_TOMCAT_INSTALL_DIR>\bin
    shutdown