Jersey 1.x - Hello, world!

Developing RESTful Web services that seamlessly support exposing your data in a variety of representation media types and abstract away the low-level details of the client-server communication is not an easy task without a good toolkit. In order to simplify development of RESTful Web services and their clients in Java, a standard and portable JAX-RS API has been designed. Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.

This tutorial shows how to develop a simple hello world RESTful application using Jersey 1.19. This tutorial uses Eclipse for Java EE developers and Apache Tomcat as the development tools. If you do not have them, please setup them before continuing this tutorial.

For Ubuntu users:
For any users:
Integrate Tomcat with Eclipse

Step 1:
Create a new “Dynamic Web Project” in Eclipse, by NewProjectDynamic Web Project.

Step 2:
Give the project name as “Jersey Demo” and click “Finish”, on the appeared dialog.

Step 3:
We need to create “web.xml” file in the WebContentWEB-INF folder. It will be created automatically, if the  Dynamic Web Module version is lower than 3.0; otherwise right click on the “Deployment Descriptor: Jersey Demo” and choose “Create Deployment Descriptor Stub”.

Step 4:
Using Maven, make library management easier than the pure Eclipse project. To convert this project to Maven project, right click on the project and select ConfigureConvert to Maven Project.

Step 5:
Provide the group id – “com.javahelps” and artifact id – “jerseydemo” in the appeared dialog, and click on the “Finish” button.

Step 6:
Add the following dependencies to the "pom.xml" file.


After modification, pom.xml should look like this:
<project xmlns="" xmlns:xsi=""



Step 7:
Expand the src folder in the “Java Resources” and create a new package inside it.

Step 8:
Give the package name as “com.javahelps.jerseydemo

Step 9:
Right click on the package and select NewClass to create a new Java class “HelloWorldService”.

Step 10:
Modify the class as shown below.
package com.javahelps.jerseydemo;


public class HelloWorldService {

    public Response sayHello(@PathParam("name") String msg) {
        String output = "Hello, " + msg + "!";
        return Response.status(200).entity(output).build();

  • @Path("/sayhello") - The URL of this service is /sayhello.
  • @GET - This method is handling the Http method GET.
  • @Path("/{name}") - The URL for the specific method. In this case it can be any name, which will be passed as a parameter to the method.

Step 11:
Modify the web.xml which is available in WebContentWEB-INF as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
    <display-name>Jersey Demo</display-name>
        <!-- Define ServletContainer of Jersey -->
        <!-- Define the package to search for classes -->

    <!-- Map all the URLs to the Jersey ServletContainer -->

Step 12:
Save all the changes and run the project.
To run the project, right click on the project and select Run AsRun on Server.

Step 13:
Enter a URL in the following format and check the output.

For example:

Find the project at Git Hub.
Next Post »

Contact Form


Email *

Message *