hyperlink hyperlink - 2 years ago 79
Java Question

What is the fastest way to stand up a REST service using Java?

I have a few utility methods that I wrote in Java, for test data creation against a service. A couple of my colleagues who have the same use case thought it would be cool if they could re-use it, but they are writing their tests in Perl and Python respectively. So I am thinking of standing up a JSON REST service that would expose these methods.

I have limited experience writing web-apps. What would be the fastest way to stand up and deploy my service?

I am thinking of using eclipse/spring to do it and ant to deploy on a Jetty container. But I would like to hear your experiences about this. Also it seems some IDEs/Plugins have better support for some technologies than others. So I would like to hear what IDE/Plugins + J2EE Technology stack + Server(If that matters) is a good combination for my usecase and why. I would like to stick to open source software.

Answer Source

I believe using Maven gets you up as fast as one can. Here's how you can do it.

It uses the RESTEasy implementation of JAX-RS (the Java API for RESTful Web Services, an official part of Java EE 6).

This is a java war maven project with the bare minimum structure. These are the files:


I called it simpleRest as seen below. All the archives are exactly as shown:


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"


                <!-- So maven doesn't require web.xml -->


package rest;

import java.util.Date;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

public class HelloResource {
    public String helloResource() {
        return "Hello! It's "+new Date();


package rest;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

public class JaxRsActivator extends Application {


This generates a simpleRest.war (through mvn clean package). You can deploy it to a freshly installed JBoss AS 7.1.1.Final (just throw the war file in the deploy folder) or a Tomcat.

After that, the URL is available as expected:

How quick is that?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download