logo

How To Use Maven Jetty Plugin

How to use Maven Jetty plugin for embedded Jetty web container. Jetty is popular Java EE servlet container. Jetty run, stop and configuration.

You can run your web applications on an embedded web container. Now I will show you how to use Jetty. 

 

But first a little bit about Jetty. It's a web container like Apache Tomcat. If you google Jetty, you will see Jetty on Codehaus and Eclipse. Jetty was a long time Codehaus project, but later it was moved to Eclipse Foundation. 

 

Which version should you use depends on your Java SE and Java EE version. Let's see a documentation. There's "What version do I use?" and there's version 9, 8, 7. Version 9 requires Java SE 7 and implements Java EE 6. 

 

To use Jetty 9 in your project add this plugin to your pom.xml file:

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

To use Jetty 8 go to Codehaus, there's documentation and use this plugin instead:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>8.1.14.v20131031</version>
</plugin>

To run Jetty server, run your Maven application with goal:

jetty:run

To stop Jetty server click on button Terminate in Eclipse.

 

You can also stop Jetty server using goal jetty:stop, but you have to configure it first:

 

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

 

And then if I run goal jetty:run, I can use goal jetty:stop to stop this Jetty instance.

 

There are lot's of configuration options, see documentation.


comments powered by Disqus

rss

Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects:
github

Search