Rego’s Everyday Life

A blog about my work at Igalia.

JAX-RS example with Jersey, Jetty and Maven

Last weekend I’ve been giving the last lesson of the Web module at Master on Software Libre. In this lesson we’ve tried to advance as much as possible in the practice that the students are developing for this module, a web application using Java technologies: Maven, Hibernate, Jetty and ZK. The last part of this practice has the aim to create web services around this web application based on REST standard. In order to properly explain how this goal could be achieved I’ve created a small example that could be useful for more people.

The Java API for RESTful Web Services is called JAX-RS (and it’s defined at JSR-311) and the reference implementation is Jersey. I’ve tried to find an example using Jersey, Jetty and Maven about how to add REST web services to a Java application, after failing in my search I decided to start my own example based in a post by Tim Reardon.

These kind of services are intended to import/export data from/to a web application, the most common formats are XML and JSON. For this example I decided to use XML, using JAXB standard to map Java classes to XML files.

The final result is a simple application implementing the different HTTP methods (GET, POST, PUT and DELETE) that could help to other developers as example. Along with several bash scripts to to test the web service, I’ve also added a basic client written in Java. You can find the example application uploaded to Gitorious and you can download the source code from there.


Comments

On 10/08/25 00:28, **Greg Wilkins** wrote:

Your readme should say “mvn jetty:run” instead of “mvn jetty-run”.

cheers

On 10/08/25 10:50, Manuel Rego Casasnovas wrote:

You’re right, I’ve just changed it. Thanks for the feedback.

On 12/01/03 20:42, Matthew Cornell wrote:

The link [post by Tim Reardon] is broken – http://blog.reardonsoftware.com/2009/03/jersey-jetty-and-maven-helloworld.html . I found this one: http://codebeneath.blogspot.com/2008/03/jersey-jetty-and-maven-style.html , which is older.

On 12/11/17 01:40, Mike wrote:

Was disappointed that the attached code has nothing to do with Jetty as the title states.

On 10/08/25 10:50, Manuel Rego Casasnovas wrote:

Mike I don’t understand your comment.

This is just an example of a JAX-RS application running in Jetty with Maven. Maybe, it’s not very related to Jetty, but in the README the instructions explain how to run the example in Jetty and not with any other servlet container.