Create Simple Java RESTful Web Services Using Jersey

In this tutorial you will learn how to create simple Java RESTful web services using Jersey framework.

JAX-RS is the Java API used for creating RESTful web services. There are mainly two types of implementation of JAX-RS that are Jersey and RESTeasy. In this tutorial we will see Jersey implementation.

We will use eclipse to create our web service. Make sure it contains apache tomcat server. You can follow below link to know how to download and configure tomcat.

Read: Configure Apache Tomcat Server in Eclipse IDE

Create Simple Java RESTful Web Services Using Jersey 1

Also Read: Create Java SOAP Web Service Using Eclipse

How to Create Java RESTful Web Services Using Jersey Framework

1. First of all download the Jersey jars from below link.

2. Open eclipse and go to File -> New -> Dynamic Web Project to create a dynamic web project with name JavaRESTfullWS.

3. Now we have to import jersey jars in our project. The file that you have downloaded in previous step is compressed file. After extracting it you will get several folders. Just import all the jars present in those folders. You can follow below link if you don’t know how to import jars in eclipse.

4. Create a package with name example under src folder in your project. Under this package create a source file with name DemoService and add following code inside it.

package example;


public class DemoService {
	public String printMsg(@PathParam("msg") String msg){
		return "<h1>Your message: "+msg+"</h1>";


5. Enter following code in web.xml file. You can find it under Web-Content -> WEB-INF folder. If it is not there then create one.


<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi=""   
id="WebApp_ID" version="3.0">  

    <servlet-name>Jersey REST Service</servlet-name>  
    <servlet-name>Jersey REST Service</servlet-name>  


The project has following structure.

Create Simple Java RESTful Web Services Using Jersey 2
6. Right click on your project folder and then select Run As -> Run on Server.

7. For testing the web service open following url in browser.


Create Simple Java RESTful Web Services Using Jersey 3

You can change Hello at the end of the url to pass some other message as parameter.

Video Tutorial

You can watch below video. Everything is explained in it step by step.

Comment below if you are facing any difficulty to create Java RESTful web services.

Happy Coding!! 🙂 🙂

4 thoughts on “Create Simple Java RESTful Web Services Using Jersey”

  1. Create a package something like com.tutorial.jersey and add same in web.xml. example is like folder not a pachage. I guess this was the problem and it solved for me

Leave a Comment

Your email address will not be published. Required fields are marked *