Rapid Testing Using the Jetty Plugin

Normally, testing a web application involves compiling java sources, creating a war and deploying it to a web container.

But using the Jetty plugin enables you to quickly test your web application by skipping the last two steps. By default the Jetty plugin scans your target/classes for any changes in your java sources and src/main/webapp for your web sources. The Jetty plugin will automatically reload the modified classes and web sources.

To use the Jetty plugin just add the following in your pom.xml:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8080</port>
              <maxIdleTime>60000</maxIdleTime>
            </connector>
          </connectors>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

Then start Jetty:

  mvn jetty:run

The command will block with Jetty listening on port 8080.

Check the Jetty plugin documentation for more details.