Jersey 2.5 + Maven = easy REST web services

What is covered

In this blog, I DO NOT explain about Jersey.
Here, I explain integrating Jersey with Maven to create a quick RESTful web service.

To know about setting up Maven to create Dynamic Web Project, refer to my log named

Maven + Dynamic Web Project = Ouch. How do I run it on eclipse?

I have used the following softwares
  • Eclipse: Kepler
  • JDK: 1.7
  • Compiled in JDK 1.6
  • Servlet 3.0
  • Tomcat 7

Update pom.xml

The first thing we do is to update pom.xml to load all the JARs required for Jersey.


We need to add "jersey-container-servlet-core" as a dependency if we are developing webapp for Servlet version older than Servlet 3.0.

Update we.xml

Add the following servlet mappin
  <servlet-name>Jersey Web Application</servlet-name>
  <servlet-name>Jersey Web Application</servlet-name>

One of the visible differences between Jersey 1.x and 2.x is the package. Jersey 1.x has package com.sun.jersey, whereas Jersey 2.x has package structure org.glassfish.jersey.

ServletContainer is the servlet that integrates Jersey to web application. And as expected, any URL pattern that matches the goes through the servlet.
The init parameter "jersey.config.server.provider.packages" is a list of packages in which Jersey searches for @Path annotation. These become the RESTful services.

You might want to make sure you are running Servlet 3.0 by looking at the web.xml's schema. If not, you could copy this down

<web-app xmlns:xsi=""  xmlns=""  xsi:schemaLocation=""  id="WebApp_ID" version="3.0">   <display-name>MyWebProject</display-name> </web-app>

Sample Class

Following is a sample class that we could use


public class SampleWebService {
 public String sayHello() {
  return "Hello, how are you?";

Now deploy the application on server, and hit the REST URL. In my case it is

It works!

You will see "Hello, how are you?" written on your browser :)

I hope this works for you. But if it doesn't, make sure you follow the steps mentioned in another blog entry "Maven + Dynamic Web Project = Ouch. How do I run it on eclipse?"

Feel free to contact me at



  1. if the version number is 2.22.1, then jersey-container-servlet-core is automaticaly included in jersey-container-servlet.



Post a Comment