RESTEasy tutorial

User Rating: 4 / 5

Star activeStar activeStar activeStar activeStar inactive

RESTEasy is an portable implementation of JAX-RS specification which provides a Java API for RESTful Web Services over the HTTP protocol. In this tutorial we will show a step-by-step guide how to create some simple RESTful Web services using Resteasy implementation.

Installing RESTEasy

Installing RESTEasy requires different steps depending on the release of JBoss AS you are running:

JBoss 6/7

If you are going to run RESTEasy with JBoss 6/7 you don't have to download/install anything. The RESTEasy libraries are already bundled in the application server. Also the application server detects automatically the resources which are exported as Restful services.


  Checkout this tutorial if you want more examples about RESTEasy and JBoss AS 7.

All you have to do is inserting the correct web.xml namespaces:

<web-app version="3.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">


Older JBoss releases

If you have got any other JBoss AS release you have to perform a few basic steps for installing RESTEasy:

Step 1# Download Resteasy from the Repository

The first step is to download the latest Resteasy stable release from:

Step 2# Add the following libraries to your Web application:


Step 3# Define listeners and bootstrap classes:

Add the following web.xml configuration:

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    <display-name>RestEasy sample Web Application</display-name>






The org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap class is a ServletContextListener that configures an instance of an ResteasyProviderFactory and Registry.

Then, you need to set the parameter with the singleton class which is used by your application to enlist all JAX-RS root resources and providers. Using JBoss 6-M4 and Higher this is not necessary as it's performed automatically by the application server when you deploy the .war

Finally you need to specify which url patterns need to be filtered by Resteasy. With the /* url-pattern all resources will be passed to resteasy servlet.

Step 4# Create the Singleton class

Now we need to add a special Singleton class to enlist all JAX-RS resources, as indicated by the parameter.

package sample;

import java.util.HashSet;
import java.util.Set;

import sample.HelloWorld;

public class HelloWorldApplication extends Application
    private Set<Object> singletons = new HashSet();
    private Set<Class<?>> empty = new HashSet();

    public HelloWorldApplication() {
        this.singletons.add(new HelloWorld());

    public Set<Class<?>> getClasses()
        return this.empty;

    public Set<Object> getSingletons()
        return this.singletons;

This is your Application class which will enlist your RESTful services in the constructor. In our example, we will add the HelloWorld service.

Autoscanning of resources

If you prefer, you can let RESTeasy scan for your resources instead of adding the SingletonBean which installs your JAX-WS resources.  Just add the following configuration in your web.xml: