Configuring the Jetty Plugin
Once youâve compiled, tested, and packaged your web
application, youâll likely want to deploy it to a servlet container
and test the index.jsp that was
created by the Maven Archetype plugin. Normally, this would involve
downloading something like Jetty or Apache Tomcat, unpacking a
distribution, copying your applicationâs WAR file
to a webapps/ directory, and then
starting your container. Although you can still do such a thing, there
is no need. Instead, you can use the Maven Jetty plugin to run your
web application within Maven. To do this, weâll need to configure the
Maven Jetty plugin in our projectâs pom.xml. Add the plugin
element shown in Example 5-2 to your projectâs build
configuration.
Example 5-2. Configuring the Jetty plugin
<project> [...] <build> <finalName>simple-webapp</finalName> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> </plugins> </plugins> </build> [...] </project>
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 as follows:
~/examples$ mvn jetty:run ... [INFO] [jetty:run] [INFO] Configuring Jetty for project: simple-webapp Maven Webapp [INFO] Webapp source directory = \ /Users/tobrien/svnw/sonatype/examples/simple-webapp/src/ main/webapp [INFO] web.xml file = \ /Users/tobrien/svnw/sonatype/examples/simple-webapp/src/ ...
Get Maven: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.