RESTful Web Services Developer's Guide

Chapter 2 Installing Jersey and the Jersey Sample Applications

The chapter describes how to download and install Jersey onto the GlassFishTM container. It also describes how to download the Jersey plugin for NetBeansTM.

Installing Jersey on GlassFish

The following section provides details for installing Jersey on Sun GlassFish Enterprise Server v3 Prelude (hereafter referred to as GlassFish v3 Prelude, or simply GlassFish). These steps assume that GlassFish is installed on your system. Jersey is installed as an add-on to GlassFish using the Update Tool that ships with GlassFish. The sample applications that ship with Jersey are also installed during this step.

ProcedureAdding Jersey to GlassFish

This task describes how to download and add Jersey technology to the GlassFish container.

  1. Start the Update Tool.

    There are several ways to start the Update Tool. Here a few of the options:

    • From the Windows Start menu, select GlassFish v3 Prelude, then select Start Update Tool.

    • From a Windows file browser or command prompt, or from a Unix terminal prompt, change to the directory where GlassFish was installed, then the bin directory, and run updatetool.exe (Windows) or updatetool (Unix).

    • From a web browser, open the Admin Console by going to http://localhost:4848, then select Update Tool from the left pane.

  2. Click Available Add-ons.

  3. Select Jersey RESTful Web Services for GlassFish.

  4. Click Install.

  5. Accept the license.

Installing Jersey in NetBeans

The RESTful Web Services plugin comes bundled with NetBeans IDE 6.5 when you select a NetBeans Pack that includes Java Web and EE. No additional steps are needed to configure and use the Jersey APIs with one of these NetBeans packs. If you've installed a pack that doesn't include Jersey, use the update center to install it.

Installing and Running the Jersey Sample Applications

Jersey includes a very thorough collection of sample applications intended to help you become acquainted with using the RESTful APIs. Several of the sample applications are referenced for sample code throughout this tutorial, and several of the sample applications are discussed in some detail in Chapter 5, Jersey Sample Applications

Installing the Jersey Sample Applications

If you have installed the Jersey add-on to GlassFish, you will find the sample applications in the directory as-install/jersey/samples.

If you installed Jersey as part of the NetBeans IDE, you will have to download the sample applications from the repository. To download the version of the samples that are shipping with Jersey FCS 1.0, click here.

Running the Jersey Examples

The Jersey sample applications are built, run, and deployed using Maven. Maven is a software project management tool, similar to Ant. Ant is a build tool for Java programs. Maven is also a build tool, and can in fact run Ant targets, but Maven adds an organization and structure layer to make the build process easier, to provide a uniform build environment, and to generate quality project information.

Procedure Running the Examples from the Command Line

After you have downloaded the Jersey samples, follow these steps to run the samples from the command line.

  1. Download and install Maven 2.0.9 or higher from the Apache Maven Project web site at Make sure to follow the instructions in the Maven README.html file which include adding the maven/bin directory to your path statement.

  2. In a terminal window or command prompt, change to the directory for the sample application you'd like to run. For example, to run the HelloWorld sample, change to jersey/samples/helloworld.

  3. Read the README.html file for the sample, and follow the steps listed for running the sample. For example, to run the HelloWorld sample, run mvn compile exec:java, and follow the instructions on the screen and in the README.html file.

ProcedureRunning the Jersey Examples from NetBeans

To run the Jersey samples from NetBeans, follow these steps.

  1. If you didn't do this in the previous task, download and install Maven 2.0.9 or higher from the Apache Maven Project web site at Make sure to follow the instructions in the Maven README.html file which include adding the maven/bin directory to your path statement.

  2. From the NetBeans IDE, install the Maven plugin. To do this, select Tools->Plugins, select Maven, click Install, and follow the prompts.

  3. Configure Maven in NetBeans IDE. To do this, select Tools->Options, select Miscellaneous from the top panel, then select the Maven tab.

  4. For the External Maven Home field, browse to your Maven installation.

  5. If the option is available, check Always use external Maven for building projects. Close the dialog.

  6. From the NetBeans IDE, select File->Open Project, and then browse to the location of the project you'd like to open, for example, jersey/samples/helloworld.

  7. Check Open as Main Project, then click Open Project.

  8. Right-click the project and select Run.

  9. Follow the instructions from the prompt. For example, if you're running HelloWorld, enter http://localhost:9998/helloworld in a web browser.