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.
This task describes how to download and add Jersey technology to the GlassFish container.
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
http://localhost:4848, then select Update Tool from
the left pane.
Click Available Add-ons.
Select Jersey RESTful Web Services for GlassFish.
Accept the license.
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.
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
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.
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.
After you have downloaded the Jersey samples, follow these steps to run the samples from the command line.
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.
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.
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.
To run the Jersey samples from NetBeans, follow these steps.
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.
From the NetBeans IDE, install the Maven plugin. To do this, select Tools->Plugins, select Maven, click Install, and follow the prompts.
Configure Maven in NetBeans IDE. To do this, select Tools->Options, select Miscellaneous from the top panel, then select the Maven tab.
For the External Maven Home field, browse to your Maven installation.
If the option is available, check Always use external Maven for building projects. Close the dialog.
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.
Check Open as Main Project, then click Open Project.
Right-click the project and select Run.
Follow the instructions from the prompt. For example, if you're running HelloWorld, enter http://localhost:9998/helloworld in a web browser.