The Java API for RESTful web services (JAX-RS) is a Java language specification that simplifies the development and deployment of RESTful web services. RESTEasy is JBoss's implementation of the JAX-RS specification.

In this post, I will walk you through the steps I followed when getting started with the RESTEasy framework.


  • OpenJDK for Java 1.8
  • Git
  • Maven (I'm using 3.3.9)
  • The Eclipse IDE for Java EE Developers (I'm using Neon)

Note: This post will walk you through the steps required to install the OpenJDK. And, this post will walk you through the steps required to install Git, Maven and the Eclipse IDE.

What is an Archetype?

An archetype is "an original pattern or model from which all other things of the same kind are made". We can use Maven's quickstart archetype to create a template for our project:

mvn archetype:generate \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DarchetypeVersion=1.1 \
  -DgroupId=org.robferguson.resteasy.examples.helloworld \
  -DartifactId=helloworld \
  -DarchetypeRepository=local \

Note: For line continuation to work the backslash ('\') must be the very last character before the end of line character, if there is a space after the '\', the line continuation will not work.

You should see output like:

[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------
[INFO] Generating project in Batch mode
[INFO] ----------------------------------------------------------------
[INFO] Parameter: packageName, Value: helloworld
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ----------------------------------------------------------------
[INFO] ----------------------------------------------------------------
[INFO] Total time: 7.316 s
[INFO] Finished at: 2016-11-26T09:49:24+11:00
[INFO] Final Memory: 18M/121M
[INFO] ----------------------------------------------------------------

The Eclispe IDE

Now we can import the template into the Eclispe IDE, select 'File -> Import...':

Select 'Existing Maven Projects', then click the Next button:

Select the project's root directory, click the Finish button, then take a look at the project's structure in the Project Explorer:

Creating a Resource

Now we're ready to create our first resource, lets take a look at a simple example:


public class MessageResource {

  public Response printMessage(@PathParam("param") String msg) {
    String result = "Hello " + msg + "!";
    return Response.status(200).entity(result).build();

JAX-RS relies heavily on annotations to simplify the development of RESTful web services. The @Path annotation specifies the relative path (i.e., "/hello") for a resource class or method. The @GET annotation specifies the HTTP request type and the @PathParam annotation binds the method parameter to a path segment (e.g., "World").

Registering a Resource

We can extend the class in order to tell RESTEasy which resources we want deployed.

Let’s take a look at a simple example:


public class HelloWorldApplication extends Application {

  public HelloWorldApplication() {}

  public Set<Object> getSingletons() {
	HashSet<Object> set = new HashSet<Object>();
	set.add(new MessageResource());
    return set;

The Application class is very straightforward, it lists the classes and objects that JAX-RS is supposed to deploy. It also includes the @ApplicationPath(“”) annotation which defines the relative base URL path (e.g., @ApplicationPath("") -> http://localhost:8080 or @ApplicationPath("api") -> http://localhost:8080/api) for all our JAX-RS services.

The getSingletons() method returns a list of preallocated (i.e., objects that you have created) JAX-RS web services and providers. The RESTEasy runtime will iterate through the list of objects and register them internally. When the objects are registered, RESTEasy will also inject values for @Context annotated fields and setter methods.


RESTEasy applications can be deployed to a servlet container like Jetty or Tomcat or to a JEE application server like JBoss Wildfly or IBM Websphere. They can be packaged in a WAR or as a fat JAR.

To deploy a RESTEasy application to a JAX-RS-aware servlet container we only need a very minimal web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""

If you have at least one Application class implementation annotated with @ApplicationPath, a JAX-RS–aware servlet container will deploy your application by using the Servlet 3.0 ServletContainerInitializer Service Provider Interface (SPI).


The Project Object Model contains everything we need to know about a project (the "who", "what", and "where") including the plugin configurations used during the build process (the "when" and "how").

Note: Maven favours convention over configuration which means it will look for code to compile in the src/main/java directory, for the web.xml file in the src/main/webapp directory, and for tests in the src/test/java directory.

Let’s take a look at the Hello World example's pom.xml:


The first few elements — the groupId, artifactId, version and packaging — are known as the Maven coordinates, and they uniquely identify a project.


Maven properties are value placeholders, their values are accessible anywhere within a POM using the following notation: ${X} (e.g., ${resteasy.version}).


  <!-- Runtime dependencies -->
  <!-- Test scope dependencies -->

The dependencies element lists all the library dependencies the project needs to compile and run.

The Hello World example is dependent on RESTEasy (the core library and the ServletContainerInitializer integration library) as this is the JAX-RS implementation we are using. The junit dependency has a scope of test. This means that this library is only used to run tests and is not included in the WAR.

The build element contains configuration information that defines how Maven should build the project:


The first item is the finalName element, which is used to name the project's WAR file.

Next we have the plugins element:


This section contains information about the Maven plugins that will be used to build the project. The compiler plugin, is configured to compile the project's source code into the Java 8 bytecode format.

The next plugin we need to configure is the surefire-it plugin:


The surefire-it plugin controls test execution, here you can see that we have configured the plugin to not run any tests until the WAR file has been built and deployed to Jetty.

The final plug-in is the Jetty plugin:


The Jetty plugin is responsible for running (and stopping) the embedded Jetty servlet container.

Build and run the example program

The best way to learn about the RESTEasy framework is to build and run example programs. Lets start by cloning my RESTEasy examples repository:

git clone

Then we can build the 'Hello World' example (in the examples/helloworld directory) and run some tests:

mvn clean install

To run Jetty:

mvn jetty:run

You should see output like:

[INFO] --- jetty-maven-plugin:9.0.6.v20130930:run
[INFO] Configuring Jetty for project: helloworld
INFO: RESTEASY002225: Deploying class
INFO: RESTEASY002220: Adding singleton resource
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.

In your browser navigate to:


You should see output like:

To stop Jetty:

mvn jetty:stop
Source Code: