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.