Supporting mvn jetty:run in Maven applications

jetty-header-logo

When I’m writing a Java servlet using Maven, I find it convenient to be able to run the Java servlet in a local servlet container for testing purposes.  This is very easy to do using the Jetty Maven plugin.

To add the Jetty Maven plugin to your project, modify pom.xml as follows:

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.2.0.M0</version>
    </plugin>
  ...
  </plugins>
</build>

You can then run your project in Jetty using the following command:

mvn jetty:run

If you want to run the website from the compiled WAR rather than from the source code, then use the following configuration:

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.2.0.M0</version>
      <configuration>
        <war>${basedir}/target/${project.build.finalName}.war</war>
      </configuration>
    </plugin>
  ...
  </plugins>
</build>

Then execute:

mvn jetty:run-war

About Steven Engelhardt, CFA, AIF
Adjunct Professor of Software Engineering at DePaul University • Software Engineering, Data & Analytics in FinTech • Lives in Chicago, IL

One Response to Supporting mvn jetty:run in Maven applications

  1. Pingback: Publishing a Java Servlet to Azure Website Using Maven | Steven Engelhardt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s