Restful Webservice HelloWorld Jersey 2.x Example

Jersey 1.x team joined with GlassFish and all new upgrades are released under Jersey 2.x. Check the details in Jersey official website. Last tutorial we have seen Restful Webservice example using Jersey 1.x , In this tutorial we will see the same Restful Webservice example with Jersey 2.x . Follow the step by step procedure to migrate from jersey 1.x to jersey 2.x.

Create maven web application project and add Jersey dependency in pom.xml. Find Jersey 2.x maven dependency configuration below. If you are new to maven refer our maven tutorials.

Jersey 2.x dependency in pom.xml

First update the pom.xml with jersey 2.x dependency.

<project xmlns="" xmlns:xsi=""
  <name>RestTutorials Maven Webapp</name>
      <!-- JAX-RS -->
        <!-- Jersey 2.19 -->

Configure Jersey 2.x Servlet dispatcher

Second update the web.xml. ServletContainer class moved to “org.glassfish.jersey.servlet” package. Init param to configure Rest class packages name changes to “jersey.config.server.provider.packages”, other annotations are remains same they are as pers JAX-RS standards.

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

	<display-name>Restful Webservice Example</display-name>


package com.ehowtonow.webservice;


public class RestHelloWorld {
 public String sayHello(){
  return "Welcome to";
 public Response greetUser(@PathParam("userName") String userName)
     String output = "Welcome  : " + userName;
     return Response.status(200).entity(output).build();


You can access both rest apis using below url. http://localhost:8080/RestTutorials/rest/hello http://localhost:8080/RestTutorials/rest/hello/Annamalai See the output below.

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. JAX-RS Web service to Consume JSON using Jersey 1.x
  2. Download PDF file using JAX-RS RESTful Webservice
  3. JAX-RS get QueryParam using @Context UriInfo
  4. Download Excel file using JAX-RS RESTful Webservice
  5. Restful Webservice HelloWorld Jersey 2.x Example
  6. JAX-RS @FormParam Web service example
  7. JAX-RS Web Service to produce XML using JAXB
  8. Download Text file using JAX-RS RESTful Webservice
  9. JAX-RS to Produce JSON using Jackson – Jersey 1.x
  10. JAX-RS @PathParm Web service Example
  11. RESTful Web service to consume JSON and Produce XML – Jersey 1.x
  12. JAX-RS @PATH for URI – Jersey
  13. JAX-RS @MatrixParam Restful Webservice
  14. Restful Webservice HelloWorld Example Jersey 1.x
  15. File Upload using JAX-RS RESTful Webservice (Jersey 2.x)

Be the first to comment

Leave a Reply