With the jetty-maven-plugin and Servlet Annotations, it has never been simpler to start developing with Jetty! While we have not quiet achieved the terseness of some convention over configuration environments/frameworks/languages, it is getting close and only 2 files are needed to run a web application!

Maven pom.xml

A minimal maven pom.xml is need to declare a dependency on the Servlet API and use the jetty-maven-plugin.   A test project and pom.xml can be created with:

The pom.xml file is still a little verbose and the minimal file needs to be at least:

Annotated HelloWorld Servlet

Maven conventions for Servlet development are satisfied by creating the Servlet code in following source directory:

Annotations allows for a very simple Servlet file that is mostly comprised of imports:

Running the Web Application

All that is left to do is to run the web application:

You can then point your browser at http://localhost:8080/ to see your web application!

Next Steps

OK, not the most exciting web application, but it is a start.  From here you could:

  • Clone this demo from github.
  • Add more Servlets or some Filters
  • Add static content in the src/main/webapp directory
  • Create a web deployment descriptor in src/main/webapp/WEB-INF/web.xml
  • Build a war file with mvn install
Simple Jetty HelloWorld Webapp

One thought on “Simple Jetty HelloWorld Webapp

  • May 26, 2017 at 4:06 pm

    Tks. Couldn’t have been simpler.


Leave a Reply

Your email address will not be published. Required fields are marked *