Jetty Logo
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Configuring the Jetty Maven Plugin

Quick Start: Get Up and Running
Supported Goals
Configuring the Jetty Container
Configuring Your WebApp
jetty:run
jetty:run-war
jetty:run-exploded
jetty:deploy-war
jetty:run-forked
jetty:start
jetty:stop
Using Overlaid wars
Configuring Security Settings
Using Multiple Webapp Root Directories
Running More than One Webapp
Setting System Properties

The Jetty Maven plugin is useful for rapid development and testing. You can add it to any webapp project that is structured according to the usual Maven defaults. The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found. This makes the development cycle more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project, and the running web container automatically picks them up, allowing you to test them straight away.

Important

You need to use Maven 3 for jetty-7.5.3 and later releases.

Quick Start: Get Up and Running

First, add jetty-maven-plugin to your pom.xml definition:


<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
</plugin>
      
      

Then, from the same directory as your root pom.xml, type:

mvn jetty:run

This starts Jetty and serves up your project on http://localhost:8080/.

Jetty continues to run until you stop it. While it runs, it periodically scans for changes to your project files, so if you save changes and recompile your class files, Jetty redeploys your webapp, and you can instantly test the changes you just made.

You can terminate the plugin with a ctrl-c in the terminal window where it is running.

Supported Goals

The Jetty Maven plugin has a number of distinct Maven goals. Arguably the most useful is the run goal that we saw in the Quick Start section which runs Jetty on your unassembled webapp. There are other goals which help you accomplish different tasks. For example, you might need to run your webapp in a forked instance of Jetty, rather than within the process running Maven; or you may need finer grained control over the maven lifecycle stage in which you wish to deploy your webapp. There are different goals to accomplish these tasks, as well as several others.

To see a list of all goals supported by the Jetty Maven plugin, do:

mvn jetty:help

To see the detailed list of parameters that can be configured for a particular goal, in addition to its description, do:

mvn jetty:help -Ddetail=true -Dgoal= goal-name

Configuring the Jetty Container

These configuration elements set up the Jetty environment in which your webapp executes. They are common to most goals:

<connectors>

Optional. A list of org.eclipse.jetty.server.Connector objects, which are the port listeners for Jetty. If you don't specify any, Jetty configures an org.eclipse.jetty.server.ServerConnector on port 8080. You can change this default port number by using the system property jetty.port on the command line, for example, mvn -Djetty.port=9999 jetty:run. You could instead configure the connectors in a standard jetty xml config file and put its location into the jettyXml parameter.

<jettyXml>

Optional. The location of a jetty.xml file to apply in addition to any plugin configuration parameters. You might use it if you have other webapps, handlers, specific types of connectors etc., to deploy, or if you have other Jetty objects that you cannot configure from the plugin.

<scanIntervalSeconds>

The pause in seconds between sweeps of the webapp to check for changes and automatically hot redeploy if any are detected. By default this is 0, which disables hot deployment scanning. A number greater than 0 enables it.

<reload>

Default value is "automatic", used in conjunction with a non-zero scanIntervalSeconds causes automatic hot redeploy when changes are detected. Set to "manual" instead to trigger scanning by typing a linefeed in the console running the plugin. This might be useful when you are doing a series of changes that you want to ignore until you're done. In that use, use the reload parameter.

<loginServices>

Optional. A list of org.eclipse.jetty.security.LoginService implementations. Note that there is no default realm. If you use a realm in your web.xml you can specify a corresponding realm here. You could instead configure the login services in a jetty xml file and add its location to the jettyXml parameter.

<requestLog>

Optional. An implementation of the org.eclipse.jetty.server.RequestLog request log interface. An implementation that respects the NCSA format is available as org.eclipse.jetty.server.NCSARequestLog. There are three other ways to configure the RequestLog:

  • In a jetty xml config file, as specified in the jettyXml parameter.

  • In a context xml config file, as specified in the contextXml parameter.

  • In the webApp element.

See Configuring Request Logs for more information.

<stopPort>

Optional. Port to listen on for stop commands. Useful to use in conjunction with the stop or run-forked goals.

<stopKey>

Optional. Used in conjunction with stopPort for stopping jetty. Useful when used in conjunction with the stop or run-forked goals.

<systemProperties>

Optional.Allows you to configure System properties for the execution of the plugin. For more information, see Setting System Properties.

<systemPropertiesFile>

Optional. A file containing System properties to set for the execution of the plugin. By default, settings that you make here do not override any system properties already set on the command line, by the JVM, or in the POM via systemProperties. Read Setting System Properties for how to force overrides.

<skip>

Default is false. If true, the execution of the plugin exits. Same as setting the SystemProperty -Djetty.skip on the command line. This is most useful when configuring Jetty for execution during integration testing and you want to skip the tests

<useProvidedScope>

Default value is false. If true, the dependencies with <scope>provided</scope> are placed onto the container classpath. Be aware that this is NOT the webapp classpath, as "provided" indicates that these dependencies would normally be expected to be provided by the container. You should very rarely ever need to use this. Instead, you should copy the provided dependencies as explicit dependencies of the plugin instead.

<excludedGoals>

Optional. A list of jetty plugin goal names that will cause the plugin to print an informative message and exit. Useful if you want to prevent users from executing goals that you know cannot work with your project.

Configuring Your WebApp

These configuration parameters apply to your webapp. They are common to almost all goals.

<webApp>

Represents an extension to the class org.eclipse.jetty.webapp.WebAppContext. You can use any of the setter methods on this object to configure your webapp. Here are a few of the most useful ones:

<contextPath>

The context path for your webapp. By default, this is set to /.

<descriptor>

The path to the web.xml file for your webapp.

<defaultsDescriptor>

The path to a webdefault.xml file that will be applied to your webapp before the web.xml. If you don't supply one, Jetty uses a default file baked into the jetty-webapp.jar.

<overrideDescriptor>

The path to a web.xml file that Jetty applies after reading your web.xml. You can use this to replace or add configuration.

<tempDirectory>

The path to a dir that Jetty can use to expand or copy jars and jsp compiles when your webapp is running. The default is /Users/jesse/docsync/jetty-documentation/target/classes/tmp.

<baseResource>

The path from which Jetty serves static resources. Defaults to src/main/webapp.

<resourceBases>

Use instead of baseResource if you have multiple dirs from which you want to serve static content. This is an array of dir names.

<baseAppFirst>

Defaults to "true". Controls whether any overlaid wars are added before or after the original base resource(s) of the webapp. See the section on overlaid wars for more information.

<contextXml>

The path to a context xml file that is applied to your webapp AFTER the webApp element.

jetty:run

The run goal runs on a webapp that does not have to be built into a WAR. Instead, Jetty deploys the webapp from its sources. It looks for the constituent parts of a webapp in the Maven default project locations, although you can override these in the plugin configuration. For example, by default it looks for:

  • resources in /Users/jesse/docsync/jetty-documentation/src/main/webapp

  • classes in /Users/jesse/docsync/jetty-documentation/target/classes

  • web.xml in /Users/jesse/docsync/jetty-documentation/src/main/webapp/WEB-INF/

The plugin automatically ensures the classes are rebuilt and up-to-date before deployment. If you change the source of a class and your IDE automatically compiles it in the background, the plugin picks up the changed class.

You do not need to assemble the webapp into a WAR, saving time during the development cycle. Once invoked, you can configure the plugin to run continuously, scanning for changes in the project and automatically performing a hot redeploy when necessary. Any changes you make are immediately reflected in the running instance of Jetty, letting you quickly jump from coding to testing, rather than going through the cycle of: code, compile, reassemble, redeploy, test.

Here is a small example, which turns on scanning for changes every ten seconds, and sets the webapp context path to "/test":


<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
  </configuration>
</plugin>
      
      

Configuration

In addition to the <webApp> element that is common to most goals, the jetty:run goal supports:

<classesDirectory>

Location of your compiled classes for the webapp. You should rarely need to set this parameter. Instead, you should set build outputDirectory in your pom.xml.

<testClassesDirectory>

Location of the compiled test classes for your webapp. By default this is /Users/jesse/docsync/jetty-documentation/target/test-classes.

<useTestScope>

If true, the classes from testClassesDirectory and dependencies of scope "test" are placed first on the classpath. By default this is false.

<webAppSourceDirectory>

By default, this is set to /Users/jesse/docsync/jetty-documentation/src/main/webapp. If your static sources are in a different location, set this parameter accordingly.

<jettyEnvXml>

Optional. Location of a jetty-env.xml file, which allows you to make JNDI bindings that satisfy env-entry, resource-env-ref, and resource-ref linkages in the web.xml that are scoped only to the webapp and not shared with other webapps that you might be deploying at the same time (for example, by using a jettyConfig file).

<scanTargets>

Optional. A list of files and directories to periodically scan in addition to those the plugin automatically scans.

<scanTargetPatterns>

Optional. If you have a long list of extra files you want scanned, it is more convenient to use pattern matching expressions to specify them instead of enumerating them with the scanTargetsList of scanTargetPatterns, each consisting of a directory, and including and/or excluding parameters to specify the file matching patterns.

Here's an example:


<project>
... 
  <plugins>
... 
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <configuration>
        <webAppSourceDirectory>/Users/jesse/docsync/jetty-documentation/src/staticfiles</webAppSourceDirectory>
        <webApp>
          <contextPath>/</contextPath>
          <descriptor>/Users/jesse/docsync/jetty-documentation/src/over/here/web.xml</descriptor>
          <jettyEnvXml>/Users/jesse/docsync/jetty-documentation/src/over/here/jetty-env.xml</jettyEnvXml>
        </webApp>
        <classesDirectory>/Users/jesse/docsync/jetty-documentation/somewhere/else</classesDirectory>
        <scanTargets>
          <scanTarget>src/mydir</scanTarget>
          <scanTarget>src/myfile.txt</scanTarget>
        </scanTargets>
        <scanTargetPatterns>
          <scanTargetPattern>
            <directory>src/other-resources</directory>
            <includes>
              <include>**/*.xml</include>
              <include>**/*.properties</include>
            </includes>
            <excludes>
              <exclude>**/myspecial.xml</exclude>
              <exclude>**/myspecial.properties</exclude>
            </excludes>
          </scanTargetPattern>
        </scanTargetPatterns>
      </configuration>
    </plugin>
  </plugins>
</project>
        
        

If, for whatever reason, you cannot run on an unassembled webapp, the goals run-war and run-exploded work on unassembled webapps.

jetty:run-war

This goal first packages your webapp as a WAR file and then deploys it to Jetty. If you set a non-zero scanInterval, Jetty watches your pom.xml and the WAR file; if either changes, it redeploys the war.

Configuration

<war>

The location of the built WAR file. This defaults to /Users/jesse/docsync/jetty-documentation/target/jetty-documentation-9.0.2-SNAPSHOT.war. If this is not sufficient, set it to your custom location.

Here's how to set it:


<project>
... 
  <plugins>
...
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <configuration>
        <war>/Users/jesse/docsync/jetty-documentation/target/mycustom.war</war>
      </configuration>
    </plugin>
  </plugins>
</project>
        
        

jetty:run-exploded

The run-exploded goal first assembles your webapp into an exploded WAR file and then deploys it to Jetty. If you set a non-zero scanInterval, Jetty watches your pom.xml, WEB-INF/lib, WEB-INF/ classes and WEB-INF/web.xml for changes and redeploys when necessary.

Configuration

<war>

The location of the exploded WAR. This defaults to /Users/jesse/docsync/jetty-documentation/target/jetty-documentation-9.0.2-SNAPSHOT, but you can override the default by setting this parameter.

Here's how to set it:


<project> 
... 
  <plugins>
... 
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>maven-jetty-plugin</artifactId>
      <configuration>
        <war>/Users/jesse/docsync/jetty-documentation/target/myfunkywebapp</war>
      </configuration>
    </plugin>
  </plugins>
</project>
        
        

jetty:deploy-war

This is basically the same as jetty:run-war, but without assembling the WAR of the current module. Unlike run-war, the phase in which this plugin executes is not bound to the "package" phase. For example, you might want to start Jetty on the "test-compile" phase and stop Jetty on the "test-phase".

Configuration

<war>

The location of the WAR file. This defaults to /Users/jesse/docsync/jetty-documentation/target/jetty-documentation-9.0.2-SNAPSHOT, but you can override the default by setting this parameter.

Here's the configuration:


<project>
... 
  <plugins>
... 
  <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <configuration>
      <war>/Users/jesse/docsync/jetty-documentation/target/mycustom.war</war>
    </configuration>
    <executions>
      <execution>
        <id>start-jetty</id>
        <phase>test-compile</phase>
        <goals>
          <goal>deploy-war</goal>
        </goals>
        <configuration>
          <daemon>true</daemon>
          <reload>manual</reload>
        </configuration>
      </execution>
      <execution>
        <id>stop-jetty</id>
        <phase>test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
     </executions>
    </plugin>
  </plugins>
</project>
        
        

jetty:run-forked

This goal allows you to start the webapp in a new JVM, optionally passing arguments to that new JVM.

Configuration

NOTE: unfortunately, unlike most of the other goals, this one does NOT support a <webApp> parameter to configure the webapp. Therefore, if your webapp requires a lot of configuration, it will be difficult to switch between eg jetty:run and jetty:run-forked executions.

The available configuration parameters are:

<jettyXml>

The locations of jetty xml configuration files used to configure the container in the new JVM.

<contextXml>

Optional. The location of a context xml file to configure the webapp in the new JVM.

<contextPath>

Optional. The context path for the webapp in the new JVM. Defaults to /jetty-documentation. Overrides a setting inside a contextXml file.

<webAppSourceDirectory>

Optional. The location of the static resources for your webapp. Defaults to src/main/webapp. Overrides a Set name="baseResource" setting inside a contextXml file.

<resourceDirs>

Optional. An array of directories containing static content that form the resource base for your webapp, in conjunction with the webAppSourceDirectory. See also baseAppFirst.

<baseAppFirst>

Defaults to "true". Controls whether the webAppSourceDirectory or resourceDirs are first on the list of resources that form the base resource for the webapp.

<webXml>

The location of the web.xml file. Defaults to src/main/webapp/WEB-INF/web.xml. Overrides a Set name="descriptor" inside a contextXml file.

<tmpDirectory>

Temporary directory to use for the webapp. Defaults to ${project.build.directory/tmp.

<classesDirectory>

The location of the compiled classes for the webapp. Defaults to /Users/jesse/docsync/jetty-documentation/target/classes.

<testClassesDirectory>

The location of the compiled test classes for the webapp. Defaults to /Users/jesse/docsync/jetty-documentation/target/test-classes.

<useTestScope>

–Defaults to "false". If true, the test classes and dependencies of <scope>test>/scope> are placed on the webapp's classpath.

<useProvidedScope>

Defaults to "false". If true, the dependencies of scope "provided" are placed on the jetty container's classpath.

<stopPort>

Mandatory. A port number for jetty to listen on to receive a stop command to cause it to shutdown. If configured, the stopKey is used to authenticate an incoming stop command.

<stopKey>

Mandatory. A string value that has to be sent to the stopPort to authenticate the stop command.

<skip>

Optional. Defaults to false. If true, the execution of this plugin is skipped.

<jvmArgs>

Optional. A string representing arbitrary arguments to pass to the forked JVM.

To deploy your unassembled web app to Jetty running in a new JVM:

mvn jetty:run-forked

Jetty continues to execute until you either:

  • Press cntrl-c in the terminal window to stop the plugin, which also stops the forked JVM.

  • Use jetty:stop to stop the forked JVM, which also stops the plugin.

Note

If you want to set a custom port, you need to specify it in a jetty.xml file rather than setting the connector and port tags. You can specify the location of the jetty.xml using the jettyXml parameter.

jetty:start

This goal is for use with an execution binding in your pom.xml. It is similar to the jetty:run goal, however it does NOT first execute the build up until the "test-compile" phase to ensure that all necessary classes and files of the webapp have been generated. This is most useful when you want to control the start and stop of Jetty via execution bindings in your pom.xml.

For example, you can configure the plugin to start your webapp at the beginning of your unit tests and stop at the end. To do this, you need to set up a couple of execution scenarios for the Jetty plugin and use the <daemon>true</daemon> configuration option to force Jetty to execute only while Maven is running, instead of running indefinitely. You use the pre-integration-test and post-integration-test Maven build phases to trigger the execution and termination of Jetty:


<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <stopKey>foo</stopKey>
    <stopPort>9999</stopPort>
  </configuration>
  <executions>
    <execution>
      <id>start-jetty</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>start</goal>
      </goals>
      <configuration>
        <scanIntervalSeconds>0</scanIntervalSeconds>
        <daemon>true</daemon>
      </configuration>
    </execution>
    <execution>
      <id>stop-jetty</id>
      <phase>post-integration-test</phase>
       <goals>
         <goal>stop</goal>
       </goals>
     </execution>
  </executions>
</plugin>
      
      

Of course, you can use this goal from the command line ( mvn jetty:start), however you need to be sure that all generated classes and files for your webapp are already present first.

jetty:stop

The stop goal stops a running instance of jetty. To use it, you need to configure the plugin with a special port number and key. That same port number and key will also be used by the start goal.

<stopPort>

A port number for jetty to listen on to receive a stop command to cause it to shutdown.

<stopKey>

A string value sent to the stopPort to validate the stop command.

Here's a configuration example:


<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <stopPort>9966</stopPort>
    <stopKey>foo</stopKey>
  </configuration>
</plugin>
      
      

Then, while Jetty is running (in another window), type:

mvn jetty:stop

The stopPort must be free on the machine you are running on. If this is not the case, you get an "Address already in use" error message after the "Started SelectedChannelConnector ..." message.

Using Overlaid wars

If your webapp depends on other war files, thejetty:run and jetty:run-forked goals are able to merge resources from all of them. It can do so based on the settings of the maven-war-plugin, or if your project does not use the maven-war-plugin to handle the overlays, it can fall back to a simple algorithm to determine the ordering of resources.

With maven-war-plugin

The maven-war-plugin has a rich set of capabilities for merging resources. The jetty:run and jetty:run-forked goals are able to interpret most of them and apply them during execution of your unassembled webapp. This is probably best seen by looking at a concrete example.

Suppose your webapp depends on the following wars:


<dependency>
  <groupId>com.acme</groupId>
  <artifactId>X</artifactId>
  <type>war</type>
</dependency>
<dependency>
  <groupId>com.acme</groupId>
  <artifactId>Y</artifactId>
  <type>war</type>
</dependency>
          
          

Containing:


WebAppX: 

 /foo.jsp 
 /bar.jsp 
 /WEB-INF/web.xml 

WebAppY: 

 /bar.jsp
 /baz.jsp
 /WEB-INF/web.xml
 /WEB-INF/special.xml
        
        

They are configured for the maven-war-plugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <overlays>
      <overlay>
        <groupId>com.acme</groupId>
        <artifactId>X</artifactId>
        <excludes>
          <exclude>bar.jsp</exclude>
        </excludes>
      </overlay>
      <overlay>
        <groupId>com.acme</groupId>
        <artifactId>Y</artifactId>
        <excludes>
          <exclude>baz.jsp</exclude>
        </excludes>
      </overlay>
      <overlay>
      </overlay>
    </overlays>
  </configuration>
</plugin>

Then executing jetty:run would yield the following ordering of resources: com.acme.X.war : com.acme.Y.war: /Users/jesse/docsync/jetty-documentation/src/main/webapp. Note that the current project's resources are placed last in the ordering due to the empty <overlay/> element in the maven-war-plugin. You can either use that, or specify the <baseAppFirst>false</baseAppFirst> parameter to the jetty-maven-plugin.

Moreover, due to the exclusions specified above, a request for the resource bar.jsp would only be satisfied from com.acme.Y.war. Similarly as baz.jsp is excluded, a request for it would result in a 404 error.

Without maven-war-plugin

The algorithm is fairly simple, is based on the ordering of declaration of the dependent wars, and does not support exclusions. The configuration parameter <baseAppFirst> (see the section on Configuring Your Webapp for more information) can be used to control whether your webapp's resources are placed first or last on the resource path at runtime.

For example, suppose our webapp depends on these two wars:

<dependency>
  <groupId>com.acme</groupId>
  <artifactId>X</artifactId>
  <type>war</type>
</dependency>
<dependency>
  <groupId>com.acme</groupId>
  <artifactId>Y</artifactId>
  <type>war</type>
</dependency>

Suppose the webapps contain:

WebAppX: 

 /foo.jsp 
 /bar.jsp 
 /WEB-INF/web.xml 

WebAppY: 

 /bar.jsp 
 /baz.jsp
 /WEB-INF/web.xml 
 /WEB-INF/special.xml
        

Then our webapp has available these additional resources:

/foo.jsp (X) 
/bar.jsp (X) 
/baz.jsp (Y) 
/WEB-INF/web.xml (X)
/WEB-INF/special.xml (Y)
                

Configuring Security Settings

You can configure LoginServices in the plugin. Here's an example of setting up the HashLoginService for a webapp:

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
    <loginServices>
      <loginService implementation="org.eclipse.jetty.security.HashLoginService">
        <name>Test Realm</name>
        <config>/Users/jesse/docsync/jetty-documentation/src/etc/realm.properties</config>
      </loginService>
    </loginServices>
  </configuration>
</plugin>
           

Using Multiple Webapp Root Directories

If you have external resources that you want to incorporate in the execution of a webapp, but which are not assembled into WARs, you can't use the overlaid wars method described above, but you can tell Jetty the directories in which these external resources are located. At runtime, when Jetty receives a request for a resource, it searches all the locations to retrieve the resource. It's a lot like the overlaid war situation, but without the war. Here's a configuration example:

<configuration>
  <webApp>
    <contextPath>/jetty-documentation-9.0.2-SNAPSHOT</contextPath>
    <baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">
      <resourcesAsCSV>src/main/webapp,/home/johndoe/path/to/my/other/source,/yet/another/folder</resourcesAsCSV>
    </baseResource>
  </webApp>
</configuration>      
      

Running More than One Webapp

You can use either a jetty.xml file to configure extra (pre-compiled) webapps that you want to deploy, or you can use the <contextHandlers> configuration element to do so. If you want to deploy webapp A, and webapps B and C in the same Jetty instance:

Putting the configuration in webapp A's pom.xml:

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
    <contextHandlers>
      <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
        <war>/Users/jesse/docsync/jetty-documentation../../B.war</war>
        <contextPath>/B</contextPath>
      </contextHandler>
      <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
        <war>/Users/jesse/docsync/jetty-documentation../../C.war</war>
        <contextPath>/B</contextPath>
      </contextHandler>
    </contextHandlers>
  </configuration>
</plugin>
            

Alternatively, add a jetty.xml file to webapp A. Copy the jetty.xml file from the jetty distribution, and then add WebAppContexts for the other 2 webapps:

<Ref refid="Contexts">
  <Call name="addHandler">
    <Arg>
      <New class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/B</Set>
        <Set name="war">../../B.war</Set>
      </New>
    </Arg>
  </Call>
  <Call> 
    <Arg>
      <New class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/C</Set>
        <Set name="war">../../C.war</Set>
      </New>
    </Arg>
  </Call>
</Ref>      
      

Then configure the location of this jetty.xml file into webapp A's jetty plugin:

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
    <jettyXml>src/main/etc/jetty.xml</jettyXml>
  </configuration>
</plugin>      
      

For either of these solutions, the other webapps must already have been built, and they are not automatically monitored for changes. You can refer either to the packed WAR file of the pre-built webapps or to their expanded equivalents.

Setting System Properties

You can specify property name/value pairs that Jetty sets as System properties for the execution of the plugin. This feature is useful to tidy up the command line and save a lot of typing.

However, sometimes it is not possible to use this feature to set System properties - sometimes the software component using the System property is already initialized by the time that maven runs (in which case you will need to provide the System property on the command line), or by the time that jetty runs. In the latter case, you can use the maven properties plugin to define the system properties instead. Here's an example that configures the logback logging system as the jetty logger:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>properties-maven-plugin</artifactId>
  <version>1.0-alpha-2</version>
  <executions>
    <execution>
      <goals>
        <goal>set-system-properties</goal>
      </goals>
      <configuration>
        <properties>
          <property>
            <name>logback.configurationFile</name>
            <value>${project.baseUri}/resources/logback.xml</value>
          </property>
        </properties>
      </configuration>
    </execution>
  </executions>
</plugin>
      

Note that if a System property is already set (for example, from the command line or by the JVM itself), then by default these configured properties DO NOT override them (see below for use of the <force> parameter).

Specifying System Properties in the POM

Here's an example of how to specify System properties in the POM:

<plugin> 
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration> 
    <systemProperties>
      <systemProperty>
        <name>fooprop</name>
        <value>222</value>
      </systemProperty>
    </systemProperties>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
  </configuration> 
</plugin>
                

To change the default behaviour so that these system properties override those on the command line, use the <force> parameter:

<plugin> 
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <systemProperties>
      <force>true</force>
      <systemProperty>
       <name>fooprop</name>
       <value>222</value>
     </systemProperty>
    </systemProperties>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
  </configuration>
</plugin>
                

Specifying System Properties in a File

You can also specify your System properties in a file. System properties you specify in this way DO NOT override System properties that set on the command line, by the JVM, or directly in the POM via systemProperties.

Suppose we have a file called mysys.props which contains the following:

fooprop=222
                

This can be configured on the plugin like so:

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <systemPropertiesFile>/Users/jesse/docsync/jetty-documentation/mysys.props</systemPropertiesFile>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
  </configuration>
</plugin>
                

You can instead specify the file by setting the System property (!) jetty.systemPropertiesFile on the command line.

See an error or something missing? Contribute to this documentation at Github!