Developing Restful Web services using Jersey Framework for Java

Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java.
The Jersey project is part of Glassfish project sponsored by Oracle Corporation.
Jersey framework provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.

For an introduction of REST architecture please refer to REST Architecture

Developing REST using Jersey Framework and Eclipse (Quick Start for Non Maven developers)

Google search for “Download jersey client” and find the Jersey download site or download it from Jersey Project Site. The current version while writing this article is Jersey 2.22.2

Click on “Jersey JAX-RS 2.0 RI bundle” download link. Save the “” and extract it. Inside jaxrs-ri directory, there will be three directories api, ext and lib. From Jersey version 2.7 all the Jersey components are compiled with Java SE 7. So for this tutorial we are using Java SE 7.

I am using eclipse-jee-mars-1-win32-x86_64 for this tutorial.
1. Open eclipse and create a dynamic web project called myRestApp.

File -> New -> Dynamic Web Project. Provide the project name as “myRestApp”. Click Next twice. In the Web Module panel select the checkbox to “Generate web.xml deployment descriptor”. Then click Finish.

2. Under the project’s WEB-INF/lib directory copy all the jar files from all the three directories of the unzipped Jersey binaries.

a. /jaxrs-ri-2.22.1/jaxrs-ri/api
b. /jaxrs-ri-2.22.1/jaxrs-ri/ext
c. /jaxrs-ri-2.22.1/jaxrs-ri/lib

3. Under the src folder create a package of your choice. I am creating it as com.jsession4d. The eclipse screenshot is provided below.


4. Right click on the package and create a new Class file called “Hello”. The code is provided below.

package com.jsession4d;


public class Hello {

    public String sayHello(@PathParam("Name") String name) {
	return "Hello " + name;

5. Edit the web.xml file under WEB-INF as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xsi:schemaLocation="" id="WebApp_ID" version="3.0">
      <servlet-name>Jersey myRestApp</servlet-name>
   <servlet-name>Jersey myRestApp</servlet-name>

6. Now right click the project “myRestApp” and select “Run As” and then “Run On Server”.
I have already configured Tomcat in eclipse using the steps provided here. Configure Tomcat in Eclipse workspace
Right Click the project “myRestApp”, Click Export, then Click War file. Save the “myRestApp.war” War file under “webapps” directory of Tomcat. Then start Tomcat.

Now your REST application is ready to be accessed.

7. Open a browser and enter the below URL. If you get the response “Hello Mike”, you are all set and ready with your hello world REST application using Jersey.



%d bloggers like this: