Jersey Hello World Example

Jersey is a framework for developing RESTful webservices in Java. It is the JAX-RS reference implementation.

In this tutorial, we will create our first  web service using Jersey.

 

1. Technologies used

  • Jersey 2.13
  • Maven 3.0.5
  • Eclipse 4.2
  • JDK 1.6
  • Tomcat 6.0

 

2. Project structure

We create a web application project using Maven.

Jersey-Hello-World-Example-1

 

3. Jersey dependency

 

4. Add REST Service

It is an annotated Java class that provides a resource methods to handle HTTP requests.

In our case, we declared a single method sayHello(..) to handle HTTP Get requests.

The sayHello(..) method is bound to the URI path  /hello/{param}.

 

5. Web app configuration

We need to declare Jersey container Servlet to process incoming requests.

We used jersey.config.server.provider.packages in the init-param tag to indicate in which package Jersey will look for service classes.

We can achieve the same thing by using the following configuration :

Where KeyApplication is a class that defines the location of the resource classes

 

6. Test It

URL : http://localhost:8080/Jersey-Hello-World-Example/rest/hello/Walid

where param = Walid

Jersey-Hello-World-Example-2

 

Download source code