Jersey Hello World Example

8 Flares Twitter 0 Facebook 2 Google+ 6 Pin It Share 0 LinkedIn 0 8 Flares ×

Jersey is a reference implementation of  JAX-RS( JSR 311) specification. It is used to develop RESTful web services. This tutorial shows you how to develop a Hello World applications using Jersey.

Technologies used

  1. Jersey 2.5.1
  2. JDK 1.6
  3. Tomcat 7
  4. Maven 3.x
  5. Eclipse Juno

Create Project

First we need to create a maven project. This can be done using the Eclipse IDE or manually from the command prompt. Here is how you can create the maven project via the command line

mvn archetype:generate -DgroupId=com.javahash.jersey-DartifactId=JerseyHelloWorld -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

To create the project using the IDE, refer to an earlier tutorial on Spring MVC  that has a section showing the creation of maven web project using Eclipse IDE.

Jersey Project Structure


Here is the complete pom.xml showing the dependencies


In web.xml, register “com.sun.jersey.spi.container.servlet.ServletContainer“, and put your Jersey service folder under “init-param“, ““.

Declare “com.sun.jersey.api.json.POJOMappingFeature” as “init-param”. This will make Jersey support JSON/object mapping. Refer the above web.xml

Rest Service


http://localhost:8080/JerseyHelloWorld/rest/helloworld will produce a normal string response


http://localhost:8080/JerseyHelloWorld/rest/helloworld/hellojson will produce the json reponse




  • Chris

    Great post. I’ve followed the instructions and everything works except the last step. I simply end up with “{}”

    I didn’t see the code posted. Could you post it please?

  • Danielson

    com.sun.jersey.api.json.POJOMappingFeature <- is not Jersey 2, see

    for POJO upgrade

  • reader

    example is incomplete, missing the Welcome class.

  • Subhendu

    package com.javahash.jersey;

    public class Welcome {

    private String domain;
    private String message;
    public String getDomain() {
    return domain;
    public void setDomain(String domain) {
    this.domain = domain;
    public String getMessage() {
    return message;
    public void setMessage(String message) {
    this.message = message;