Apr 1, 2014

RESTEasy web service tutorial basic

Step 1: Create a maven project structure with the following archetype maven command. This assumes that Java and Maven are set up as per the previous tutorials.

mvn archetype:generate -DgroupId=com.mytutorial -DartifactId=simpleRestWeb -DarchetypeArtifactId=maven-archetype-webapp

Step 2: The above command creates a basic Java web structure.

Step 3: Import this into eclipse IDE. File --> Import

Step 4: Click "Next" and browse the folder simpleRestWeb you just created via mvn archetype plugin.

Step 5: Create the "java" source folder by right mouse clicking on simpleRestWeb folder, and then "Build Path" --> "New Souse Folder". type "src/main/java" as the folder name.

Step 6: Update the pom.xml file with the RESEasy library dependencies.

<project xmlns="" xmlns:xsi=""
 <name>simpleRestWeb Maven Webapp</name>

  <!-- JAX-RS -->
   <!-- <scope>provided</scope> -->
   <!-- <scope>provided</scope> -->
   <!-- <scope>provided</scope> -->


Step 7: Define web.xml file

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

 <display-name>Archetype Created Web Application</display-name>






This indicates that relative path will be something like /rest/*

Step 8: If you are deploying to a jboss container, define  jboss-web.xml. Otherwise the context root will be simpleRestWeb.


Step 9: Define a simple RESTful web  service interface.

package com.mytutorial;


public interface SimpleRestWeb {

 public String sayHello(@PathParam("name") String name);


Step 10: The web service implementation

package com.mytutorial;

public class SimpleRestWebImpl implements SimpleRestWeb {

 public String sayHello(String name) {
  String result = "Hello " + name;
  return result;


Step 11:  Execute mvn clean install from a DOS prompt to build the war file.

Step 12: Deploy the war file to JBoss or any other server.

Step 13:  The url to test

JBoss server with jboss-web.xml


The output is: Hello arul

If deployed to any other application server without the  jboss-web.xml


Labels: , ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home