Press "Enter" to skip to content

Simple JAX-RS Web Service on JBoss (RESTEasy)

Implementing RESTful services in PHP or Ruby was very easy, I love its simplicity compared to SOAP. But implementing a RESTful service for the first time in Java has caused me a bit of a headache. In the beginning I was quite confused when it came to JAX-RS specification and the different implementations (Jersey, RESTEasy, …), but then it’s so easy, I don’t know why I have wasted so much time figuring out what I needed…

We are using JBoss to deploy our application, which comes packed with RESTEasy, JBoss’s implementation of the JAX-RS, so setting up a project is piece of cake. The pom.xml of my project looks quite simple. The jsr311-api dependency is only needed for the time of development, as it comes with JBoss, so we can set the scope as provided. RESTEasy is also provided by the application server, so there is no need to add it to the dependencies.

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





I have created a very simple sayHello method, which takes a name:String parameter and returns a String:



public class RestExample {

    public String sayHello(@PathParam("name") String name){
        StringBuilder stringBuilder = new StringBuilder("SandBox | Hello ");

        return stringBuilder.toString();


Setting up the web.xml file:

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns="" xmlns:xsi=""  
         xsi:schemaLocation="" version="3.0">
    <display-name>Laszlo Gazsi - Sandbox</display-name>



After packaging into a war file, we are ready to deploy our test project. If we make a GET request to http://localhost:8080/sandbox/rest/hello/Laci we should see the SandBox | Hello Laci! message.