Maven by Example
   - 5.4. Configuring the Jetty Plugin

5.4. Configuring the Jetty Plugin

Configuring the Jetty Plugin. 


Once you’ve configured the Maven Jetty Plugin in your project’s pom.xml, you can then invoke the Run goal of the Jetty plugin to start your web application in the Jetty Servlet container. Run mvn jetty:run from the simple-webapp/ project directory as follows:

~/examples/ch-simple-web/simple-webapp $ mvn jetty:run
[INFO] [jetty:run]
[INFO] Configuring Jetty for project: simple-webapp Maven Webapp
[INFO] Webapp source directory = \
[INFO] web.xml file = \
[INFO] Classes = ~/svnw/sonatype/examples/ch-simple-web/\
2007-11-17 22:11:50.532::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /simple-webapp
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] Webapp directory = \
[INFO] Starting jetty 6.1.6rc1 ...
2007-11-17 22:11:50.673::INFO:  jetty-6.1.6rc1
2007-11-17 22:11:50.846::INFO:  No Transaction manager found
2007-11-17 22:11:51.057::INFO:  Started SelectChannelConnector@
[INFO] Started Jetty Server


If you are running the Maven Jetty Plugin on a Windows platform you may need to move your local Maven repository to a directory that does not contain spaces. Some readers have reported issues on Jetty startup caused by a repository that was being stored under C:\Documents and Settings\<user>. The solution to this problem is to move your local Maven repository to a directory that does not contain spaces and redefine the location of your local repository in ~/.m2/settings.xml.

After Maven starts the Jetty Servlet container, load the URL http://localhost:8080/simple-webapp/ in a web browser. The simple index.jsp generated by the Archetype is trivial; it contains a second-level heading with the text "Hello World!". Maven expects the document root of the web application to be stored in src/main/webapp. It is in this directory where you will find the index.jsp file shown in Contents of src/main/webapp/index.jsp.

Contents of src/main/webapp/index.jsp. 

    <h2>Hello World!</h2>

In src/main/webapp/WEB-INF, we will find the smallest possible web application web.xml, shown in this next example:

Contents of src/main/webapp/WEB-INF/web.xml. 

          "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
          "" >

    <display-name>Archetype Created Web Application</display-name>

Become a Member

Are you a current user of: