RESTful Web Services Developer's Guide

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 http://maven.apache.org/download.html. 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 http://maven.apache.org/download.html. 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.