Over a million developers have joined DZone.

Getting Started With RESTEasy and NetBeans IDE 7.1

DZone's Guide to

Getting Started With RESTEasy and NetBeans IDE 7.1

· Java Zone ·
Free Resource

The CMS developers love. Open Source, API-first and Enterprise-grade. Try BloomReach CMS for free.

RESTEasy is quickly becoming a favorite project of mine. RESTEasy allows you to easily and quickly create REST based services with Java. Today I’ll show you how fast you can have a minimal REST service running using NetBeans IDE 7.1 and RESTEasy.

Create a new Maven Web Application using NetBeans 7.1 and call it HelloRESTEasy.

By default an index.jsp page is created, go ahead and remove it as we won’t need it.

Now we will add the RESTEasy dependencies to the project. With NetBeans IDE this is simple. Right-click on Dependencies and select: Add Dependencies…

In the dialog that pops up enter resteasy-jaxrs into the query textbox.

My Maven pom.xml file ended up looking like this with the dependency added:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

Add a new class to the default package called: HelloService

The code for our REST service is simple. What it will do is allow us to do an HTTP GET and return a greeting. We can pass in a name and have that sent back for the greeting. Here is the code:

package com.giantflyingsaucer.helloresteasy;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
public class HelloService {
    public Response printMessage(@PathParam("name") String name) {
        return Response.status(200).entity("Hello " + name).build();

The final step before you compile the project is to add a web.xml file with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"


Build the project. Now you can take the resulting WAR file and drop it into Apache Tomcat’s webapps folder. Start Tomcat and test out the following link (make corrections to the path you setup):


Expected results:

Hello Chad




BloomReach CMS: the API-first CMS of the future. Open-source & enterprise-grade. - As a Java developer, you will feel at home using Maven builds and your favorite IDE (e.g. Eclipse or IntelliJ) and continuous integration server (e.g. Jenkins). Manage your Java objects using Spring Framework, write your templates in JSP or Freemarker. Try for free.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}