Create RESTful Web Service Hello World

Create RESTful Web Service Hello World

This demo application will show you how to create Simple Hello World Application Using JAX-RS and Jersey.

Note: If you are not familiar with RESTful web service and need depth introduction on it before developing application please read this documentation: RESTful web service introduction

In this example, the method helloWorld() is annotated with @GET and the @Produces(“text/html”) annotation. This method will process HTTP GET requests and produce content in HTML.

Below technology are needed to build application:

  • Eclipse Kepler
  • Java 1.6
  • Tomcat 7.0
  • JAX-RS 1.1
  • Jersey 1.8
  • Maven 3.0


  • Create maven project name: FirstRESTfulHelloWorld (If you are not sure how to create maven project in eclipse please follow this tutorial: Create Maven project eclipse)
  • Configure Tomcat server in eclipse (If you are not sure please follow this tutorial: Configure Tomcat server in eclipse)
  • Now create package name: com.javahonk inside src/main/java folder
  • Create class name and copy paste below code:
package com.javahonk;


public class HelloWorld {

	 public String helloWorld() {

		return "<html> " + "<title>" + "Hello World!" + "</title>"+ "<body><h1>" + "Hello World!" + "</body></h1>" + "</html> ";




  • Create index.jsp inside webapp and copy paste below code:
<title>Hello World!</title>
	<h2>Show me first RESTful Hello World!</h2>

	<form id="userForm" action="rest/user/helloWorld" method="GET">
				<td><input type="submit" value="Submit" /></td>				



  • Copy paste below maven dependency jar into your pom.xml file:
<project xmlns="" xmlns:xsi=""
  <name>RestFulService Maven Webapp</name>
  • Now copy paste below code in your web.xml file:
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

  <display-name>First RESTful Hello World</display-name>





  • After all steps your project should look as below:

Create RESTful Web Service Hello World

  • Now refresh and clean your project.
  • To run project: Right click project –> Run As –> Run on Server
  • You will see below first index.jsp page click Submit button:

Create RESTful Web Service Hello World


  • Once you click submit button you will see below Hello World page:

Create RESTful Web Service Hello World


  • That’s it. We have created our first RESTful web service.

download2 Download project: FirstRESTfulHelloWorld

Leave a Reply

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

I am not Robot *