Sample REST Web Service (JAX-RS)

In this tutorial I will show how to create a sample JERSEY REST Web Service. We will create Web Service using Maven and will run it on the Tomcat. This tutorial is using:

1) Tomcat 7.0

2) Java 1.6

3) Jax-RS Web Service

4) Maven

5) Eclipse


First we need to create a maven web project.  You can create the maven project with command prompt (mvn archetype:generate -DartifactId=RestExample -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false) or from the eclipse (File > New > Project > Maven Project)


In the pom.xml following dependencies needs to be added for JERSEY APIs.






Now in web.xml need to make following entry for Jersey Servlet:






  <param-value></param-value> (//This needs to be the same package name where we will be creating the rest web service classes)









After making the required entries, we can start with writing a REST web service.  Create a class and annotate it with @Path to make it as web service.










public class HelloWorld {




public Response getMessage(@PathParam(“param”) String msg){

String output = “Hello World : “+msg;

return Response.status(Status.OK).entity(output).build();



Now build the project by using below command :

mvn clean install

It will create the .war file in the target folder.  Just deploy the .war file in the tomcat WEBAPPS directory.  Start the tomcat server.

On the browser or through any REST client (DHC or Postman), hit the REST URL. For the service that we have created it should be:


where message can be any value mapped with {param}.

This is the sample example for creating GET request.  In the same way POST/PUT/PATCH/DELETE requests can be created.

In my next REST article will explain on different annotations and accept and consumes header parts.




One thought on “Sample REST Web Service (JAX-RS)

  1. Use Maven to compile and deploy the application. For this sample application, it is deployed onto Grizzly. Enter the following command from the command line in the directory Open a web browser, and enter the URL to which the application was deployed, which in this examples is

Leave a Reply

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