RESTEasy hello world example

RESTEasy, JBoss project, implementation of the JAX-RS specification. In this tutorial, we show you how to use RESTEasy framework to create a simple REST style web application.

Technologies and Tools used in this article:

  1. RESTEasy 2.2.1.GA
  2. JDK 1.6
  3. Maven 3.0.3
  4. Eclipse 3.6
What’s REST?
Read this, this and this to understand what’s REST.

1. Directory Structure

Review final directory structure of this tutorial. Just a standard web project structure.

directory structure

2. Standard Web Project

Create a standard Maven web project structure.

mvn archetype:generate -DgroupId=com.mkyong.common -DartifactId=RESTfulExample 
	-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Convert to Eclipse web project.

mvn eclipse:eclipse -Dwtpversion=2.0

3. Project Dependencies

Declares JBoss public Maven repository and “resteasy-jaxrs” in your Maven pom.xml file. That’s all you need to use RESTEasy.

File : pom.xml

<project ...">
		  <id>JBoss repository</id>

4. REST Service

A simple REST service. See demo at the end of the article, it should be self-explanatory.

public class MessageRestService {
	public Response printMessage(@PathParam("param") String msg) {
		String result = "Restful example : " + msg;
		return Response.status(200).entity(result).build();

5. web.xml

Now, configure listener and servlet to support RESTEasy. Read this JBoss documentation for detail explanation.

File : web.xml

<web-app id="WebApp_ID" version="2.4"
	<display-name>Restful Web Application</display-name>
	<!-- Auto scan REST service -->
	<!-- this need same with resteasy servlet url-pattern -->
You need to set the “resteasy.servlet.mapping.prefix” if your servlet-mapping for the resteasy servlet has a url-pattern other than “/*“.

In above example, the resteasy servlet url-pattern is “/rest/*“, so you have to set the “resteasy.servlet.mapping.prefix” to “/rest” as well, otherwise, you will hit resource not found error message.

Remember to set “resteasy.scan” to true, so that RESTEasy will find and register your REST service automatically.

6. Demo

In this example, web request from “projectURL/rest/message/” will match to “MessageRestService“, and “projectURL/rest/message/{any values}” will match to @PathParam parameter.

Test 1 : http://localhost:8080/RESTfulExample/rest/message/mkyong

example 1

Test 2 : http://localhost:8080/RESTfulExample/rest/message/hello%20world

example 2

Alternative REST Service Registration

In above example, you are register REST service via “ResteasyBootstrap” listener. Here i show you another way.

Create a class and extends, and add your REST service manually.

import java.util.HashSet;
import java.util.Set;
public class MessageApplication extends Application {
	private Set<Object> singletons = new HashSet<Object>();
	public MessageApplication() {
		singletons.add(new MessageRestService());
	public Set<Object> getSingletons() {
		return singletons;

File : web.xml , no more listener, configure your application class like below :

<web-app id="WebApp_ID" version="2.4"
	<display-name>Restful Web Application</display-name>


Download Source Code

Download it – (7 KB)


  1. RESTEasy Framework
  2. RESTEasy installation and configuration
  3. IBM : RESTful Web services: The basics
  4. RESTful Web Services
  5. Wiki : Representational State Transfer
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Pingback: ionizer loans()

  • Pingback: payment plan()

  • Pingback: auto electrician training()

  • Pingback: electrician 3 phase()

  • Pingback: house blue()

  • Pingback: zak?ad szklarski piotrków trybunalski()

  • Pingback: water ionizer loan()

  • Pingback: ben 10 plumbers badge toy()

  • Pingback: m&m locksmith()

  • Pingback: Google()

  • Pingback: electricians tool pouch leather()

  • Pingback: paypal loans()

  • Pingback: stop parking()

  • Pingback: water ionizer()

  • Pingback: stop parking()

  • Pingback: lan penge()

  • Pingback: fue()

  • Pingback: Direct TV()

  • Pingback: Direct TV vs Cable TV()

  • Pingback: watch tv show episodes()

  • Pingback: Blue Coaster33()

  • Pingback: RESTful Java Web Services()


  • Pavan

    Hello mkyong,

    This is a nice and simple explanation. I appreciate it.

    I have one question regarding the implementation. Is it possible to remove project name in the URL ? (RESTfulExample in your case) to make the URL simple by any means of configuration.



  • Sachin

    This is very nice tutorial ,But i need simple token base oAuth in my web service.I had rest easy web services running on tomcat.Can anyone suggest me how can i implement that.

    Note – Suppose that oAuth in jboss as7 and web services on tomcat.

    Thanks in advance.


    Valuable info. Fortunate me I discovered your site by accident,
    and I’m shocked why this coincidence didn’t happened in advance!
    I bookmarked it.


    Awesome! Its truly amazing post, I have got
    much clear idea regarding from this post.

  • Ed

    Great tutorial, but could use some info on packaging and running.

    mvn package

    and then to run it and test it quickly from the command line, I added the jetty plugin to the pom




    mvn jetty:run-war


    • Ed

      looks like the jetty plugin xml did not render…
      I’ll try again:



      • Ed

        Still didn’t render. I did use the “to post source code in comment tags, but the xml did not render. Sorry.

  • Steve

    Thanks for this. It worked fine for me.

    In case anyone wants to build the war using gradle rather than maven create the following build.gradle file and add this to it:

    apply plugin: ‘java’
    apply plugin: ‘war’

    repositories {

    dependencies {
    providedCompile ‘javax.servlet:servlet-api:2.5′
    compile ‘javax:javaee-web-api:6.0′
    runtime ‘javax.servlet:jstl:1.1.2′

    Then the command ‘gradle build’ will create the war file in the directory build/libs

  • Praveen

    Is it possible to have multiple prefixes

    like /rest /core

  • Ravi


    Do you have a tutorial to setup RESTEasy on Tomcat and not on JBoss AS?


    • Ravi

      Well, got it working by simple dropping the war into tomcat’s webapps dir. I thought we had to do something extra for configuring and using resteasy when not using with jboss AS.

      • Mohan

        I have deployed the application in Tomcat6.0 , while running the application
        i am getting below error
        ERROR:”HTTP Status 500 – Wrapper cannot find servlet class org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        or a class it depends on”

        please suggest me which plug in i need to add to resolve this.

      • mohan

        Hi Ravi,
        I have copied the above application in Tomact 6.0 , i have added the jars also.
        After deploying while running the application i am getting below error.Please share
        what are the extra configurations we need to do at Tomcat End.

        • Peter

          Same; I didn’t know RESTEasy won’t run on Tomcat. I’m wondering how to configure Tomcat…

  • Leo

    Does it work in cross-origin request (CORS)? I couldn’t make it work…

  • Pingback: Developing with REST APIs | I blog here !()

  • Foster

    My partner and I absolutely love your blog and find a lot of your post’s to be exactly I’m looking for. Would you offer guest writers to write content for you? I wouldn’t mind composing a post or elaborating on a few of the subjects you write about here. Again, awesome blog!

  • Clinton Lobo

    Great Tutorial. Your tutorials are always the best. Example code is working & easy to understand. Excellent templates for learning the features of JAX-RS.

  • Dilip

    The above example with Alternative REST Service Registration is working for me but it doesn’t work if I register the service via “ResteasyBootstrap” listener.
    I get this error in later case

    HTTP Status 404 – Could not find resource for relative : /message/mkyong of full path: http://localhost:8089/RESTfulExample/rest/message/mkyong

    type Status report

    message Could not find resource for relative : /message/mkyong of full path: http://localhost:8089/RESTfulExample/rest/message/mkyong

    description The requested resource (Could not find resource for relative : /message/mkyong of full path: http://localhost:8089/RESTfulExample/rest/message/mkyong) is not available.
    Apache Tomcat/6.0.29

    • Crowie

      I’m getting the same error at the moment

      • DeJu

        I am getting the same error.

    • Marco

      I have this issue running under RESIN, does anyone fixed the issue?


    • Aileroiv

      I have the same problem if I try to run the project in IntelliJ. Do you have an idea why not work for me?

  • Pingback: RESTEasy with JBOSS()

  • Pingback: RESTEasy with JBOSS()

  • Praveen Reddy


    Will it works on tomcat server.

  • Theunis de Jongh

    Hi there,

    I built my first RESTful web service with Eclipse Juno and JBoss 7, using your tutorial.

    Many thanks, you saved me a lot of bootstrapping time.

    Much appreciated :-)

  • Tim McCardle

    Thanks a lot for your examples. They are a tremendous help.

  • http://N/A Henry

    Hey mkyong,

    Thanks for putting this together. I’ve been having problems getting it working. I keep getting a java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap exception when I start my server. I can confirm my pom.xml has the dependency in place.

    Please help!
    Thanks again.

    • http://N/A Henry

      Also, when I try your source code and hit the demo URL, I get this message back:

      [8/30/2012 9:48:41 PM] System.Deployment.Application.InvalidDeploymentException (ManifestParse)

      Very lost, thanks for any help.

      • jd

        Ever resolve your manifest problem?


      • Manish Kumar

        Hi Henry,

        this problem can be solve in two ways —
        1) If you have installed both the Maven Eclipse Plugin and the Maven WTP Plugin this is automatic. If you don’t have these installed, go ahead and install them and then once Eclipse restarts right-click on the project and do a Maven > Update project…. This will internally change the project configuration so the Maven dependencies are copied to the /WEB-INF/lib folder on your deployment target.

        2) If you don’t want to use any of these plug-ins, then you have to go to the Project properties > Deployment Assembly configuration and add your dependencies manually, but again, this is done automatically by these plug-ins.

  • Paulo


    Do you know to do this HelloWorld on JBoss SwitchYard, using RESTeasy?

    I need to put a SOAP Service (already made one, that is working) with a REST service on a SwitchYard project, I’m using JBoss Developer Studio

    I’m asking your help because, in my case, your tutorial/guide doesn’t work, I don’t have any compile errors/warning, but I can’t use service on browser, I think it is because SwitchYard uses different ports (on server) and definitions (on Maven).


  • 1question

    A trivial question (sorry), how do I run this app? mvn tomcat:run ? Thanks.

  • Divyesh

    Thanks for posting article. It was useful. :)

  • Pingback: GWT+RestEasy en JBoss AS7 « Blogging googling()

  • cirovladimir

    Hi, great article!

    I’ve been able to run a REST service with the configuration you provided in a GWT application

    	<!-- this need same with resteasy servlet url-pattern -->

    , however when deploying to JBoss AS7 it fails with:
    Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NoClassDefFoundError: javax/servlet/ServletContext

    For it to work I need to change web.xml as follows


    but is really annoying having to change the web.xml file from development to deployment back and forth. Have you had this problem? Do you have any suggestion how to overcome this?


    • Fan

      Hi cirovladimir:

      I am facing the same problem you had with JBOSS AS7. May I know what exactly the changes you did on the web.xml ?


  • Pingback: JAX-RS Tutorial()

  • Pingback: Jersey hello world example()