Jersey, reference implementation to develope RESTful web service based on the JAX-RS (JSR 311) specification.

In this tutorial, we show you how to develop a simple hello world REST web application with Jersey.

Technologies and Tools used in this article:

  1. Jersey 1.8
  2. JDK 1.6
  3. Tomcat 6.0
  4. Maven 3.0.3
  5. Eclipse 3.6
If you want to know what and how REST works, just search on Google, ton of available resources.

1. Directory Structure

This is the final web project structure of this tutorial.

folder directory

2. Standard Web Project

Create a standard Maven web project structure.

mvn archetype:generate -DartifactId=RESTfulExample 
	-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
To support Eclipse, use Maven command :

mvn eclipse:eclipse -Dwtpversion=2.0

3. Project Dependencies

Jersey is published in Maven repository. To develop Jersey REST application , just declares “jersey-server” in Maven pom.xml.

File : pom.xml

<project ...>
			<name> Repository for Maven</name>

4. REST Service

Simple REST service with Jersey.

public class HelloWorldService {
	public Response getMsg(@PathParam("param") String msg) {
		String output = "Jersey say : " + msg;
		return Response.status(200).entity(output).build();

5. web.xml

In web.xml, register “com.sun.jersey.spi.container.servlet.ServletContainer“, and puts your Jersey service folder under “init-param“, ““.

File : web.xml

<web-app id="WebApp_ID" version="2.4"
	<display-name>Restful Web Application</display-name>

6. Demo

In this example, web request from “projectURL/rest/hello/” will match to “HelloWorldService“, via @Path("/hello").

And the “{any values}” from “projectURL/rest/hello/{any values}” will match to parameter annotated with @PathParam.

URL : http://localhost:8080/RESTfulExample/rest/hello/mkyong


Download Source Code


  1. Jersey Official Website
  2. RESTEasy hello world example
  3. REST with Java (JAX-RS) using Jersey – Tutorial
  4. IBM : RESTful Web services: The basics
  5. RESTful Web Services
Tags :
Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Related Posts

Popular Posts