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

Maven Jetty Plugin Configuration Guide

In order to run Jetty on a webapp project which is structured according to the usual Maven defaults (resources in ${basedir}/src/main/webapp, classes in ${project.build.outputDirectory} and the web.xml descriptor at ${basedir}/src/main/webapp/WEB-INF/web.xml, you don't need to configure anything.

Simply type:

This will start Jetty running on port 8080 and serving your project. Jetty will continue to run until the plugin is explicitly stopped, for example, by a <cntrl-c>.

It is extremely convenient to leave the plugin running because it can be configured to periodically scan for changes and automatically redeploy the webapp. This makes the development cycle much more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project and the running web container will automatically pick them up, allowing you to test them straight away.

If, for whatever reason, you cannot run on an unassembled webapp, the plugin supports the jetty:run-war and jetty:run-exploded goals which are discussed below.

Configuration Common to all Goals

Regardless of which jetty goal you execute, the following configuration parameters are common to all. They are divided into configuration that applies to the container as a whole, and configuration that applies specifically to the webapp:

Container Configuration

connectorsOptional. A list of org.mortbay.jetty.Connector objects, which are the port listeners for jetty. If you don't specify any, an NIO org.mortbay.jetty.nio.SelectChannelConnector will be configured on port 8080. You can change this default port number by using the system property jetty.port on the command line. Eg "mvn -Djetty.port=9999 jetty:run". Alternatively, you can specify as many connectors as you like.

jettyConfigOptional. The location of a jetty.xml file that will be applied in addition to any plugin configuration parameters. You might use it if you have other webapps, handlers etc to be deployed, or you have other jetty objects that cannot be configured from the plugin.

scanIntervalSecondsOptional. 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.

systemPropertiesOptional. These allow you to configure System properties that will be set for the execution of the plugin. More information can be found on them at Setting System Properties.

userRealmsOptional. A list of org.mortbay.jetty.security.UserRealm implementations. Note that there is no default realm. If you use a realm in your web.xml you can specify a corresponding realm here.

As of Jetty 6.2.0pre0 a new feature to control webapp redeployment will be available.

The configuration parameter is: <reload>[manual|automatic]</reload>

When set to manual, no automatic scanning and redeployment of the webapp is done. Rather, the user can control when the webapp is reloaded by tapping the carriage return key. Set to automatic the scanning and automatic redeployment is performed at intervals controlled by the scanIntervalSeconds parameter. The choice of reloading paradigm can also be configured on the command line by use of the -Djetty.reload system parameter.

For example: "mvn -Djetty.reload=manual jetty:run" would force manual reloading, regardless of what is configured in the project pom. Similarly: "mvn -Djetty.reload=automatic -Djetty.scanIntervalSeconds=10 jetty:run" will force automatic background reloading with a sweep every 10 seconds, regardless of the configuration in the project pom.

Webapp Configuration

contextPathOptional. The context path for your webapp. By default, this is set to the <artifactId> from the project's pom.xml. You can override it and set it to anything you like here.

tmpDirOptional. The temporary directory to use for the webapp. This is set to {${basedir}/target} by default but can be changed here.

overrideWebXmlOptional. A web.xml file which will be applied AFTER the webapp's web.xml. This file can be stored anywhere. It is used to add or modify the configuration of a web.xml for different environments eg test, production etc.

webDefaultXmlOptional. A webdefault.xml file to use instead of the supplied jetty default for the webapp.

As of release 6.1.6rc0, an alternative and more flexible way to configure the webapp is to use the webAppConfig element instead of the individual parameters listed above. With the webAppConfig element, you can effectively call any of the setter methods on the org.mortbay.jetty.webapp.WebAppContext class, an instance of which represents your webapp. The example below shows how to use this element to configure the same parameters as above (but of course there are many more you can set):

Configuration for the jetty:run Goal

The run goal allows you to deploy your unassembled webapp to jetty, based on the locations of its constituent parts in your pom.xml. The following extra configuration parameters are available:

classesDirectory This is the 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.

webAppSourceDirectory By default, this is set to ${basedir}/src/main/webapp. If your static sources are in a different location, set this parameter accordingly.

webXml By default, this is set to either the variable ${maven.war.webxml} or ${basedir}/src/main/webapp/WEB-INF/web.xml, whichever is not null. If neither of these are appropriate, set this parameter.

jettyEnvXmlOptional. it is the location of a jetty-env.xml file, which allows you to make JNDI bindings that will 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 may be deploying at the same time (eg by using a jettyConfig file).

scanTargetsOptional.A list of files and directories to also periodically scan in addition to those automatically scanned by the plugin.

scanTargetPatternsOptional. 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 <scanTargets> parameter. This parameter is a list of <scanTargetPattern>s, each consisting of a <directory> and <includes> and/or <excludes> parameters to specify the file matching patterns.

Configuration for the jetty:run-war Goal

This goal will first package your webapp as a war file and then deploy it to Jetty. If you set a non-zero scanInterval Jetty will watch your pom.xml and the war file and if either changes, it will redeploy the war.

The configuration parameters specific to this goal are:

webApp The location of the built war file. This defaults to ${project.build.directory}/${project.build.finalName}.war. If this is not sufficient, set it to your custom location.

Configuration for the jetty:run-exploded Goal

This goal first assembles your webapp into an exploded war file and then deploys it to Jetty. If you set a non-zero scanInterval, Jetty will watch your pom.xml, WEB-INF/lib, WEB-INF/classes and WEB-INF/web.xml for changes and redeploy when necessary.

The configuration parameters specific to this goal are:

webApp The location of the exploded war. This defaults to ${project.build.directory}/${project.build.finalName} but can be overridden by setting this parameter.

Setting System Properties

You may specify property name/value pairs that will be set as System properties for the execution of the plugin. Note that if a System property is found that is already set (eg from the command line or by the JVM itself), then these configured properties DO NOT override them. This feature is useful to tidy up the command line and save a lot of typing. For example, to set up Commons logging you would usually need to type:

Using the systemProperty configuration the command line can again be shorted to mvn jetty:run by placing the following in the pom.xml:

Note: You can use either <name> or <key> to specify the name of a <systemProperty>. Use whichever you prefer.

Logging

Jetty itself has no dependencies on a particular logging framework, using a built-in logger which outputs to stderr. However, to allow jetty to integrate with other logging mechanisms, if an SLF4J log implementation is detected in the classpath, it will use it in preference to the built-in logger.

The JSP engine used by jetty does however have logging dependencies. If you are using JSP 2.0 (ie you are running in a JVM version < 1.5), the JSP engine depends on commons-logging. A default commons-logging logger will be provided by the plugin using a combination of the jcl04-over-slf4j and the simple-slf4j implementation, which logs all messages INFO level and above. You can override this and provide your own commons-logging delegated logger by following these steps:

Use plugin <dependencies> add commons-logging and a commons-logging impl such as log4j onto the plugin classpath. Note that if you want the Jetty container log to also be routed to this log, you should also add the slf4j-jcl bridge jar:

Run the plugin with the system property -Dslf4j=false :

Note: if you are using log4j you will need to tell the log4j discovery mechanism where your configuration properties file is. For example:

If you are using JSP2.1 (ie you are running in a JVM >= 1.5), then rejoice because the JSP engine has no particular logging dependencies.

No labels

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