RESTful Web Services Developer's Guide

ProcedureDeploying and Testing a Jersey Application without NetBeans

The easiest way to create and run an application without NetBeans is to copy and edit one of the Jersey sample applications. We'll use the simplest sample application, HelloWorld, to demonstrate one way you could go about creating your own application without NetBeans IDE.

Before You Begin

Before you can deploy an application to GlassFish from the command line, you must have downloaded and installed Jersey onto GlassFish, as described in Adding Jersey to GlassFish.

  1. Copy the HelloWorld application to a new directory named helloworld2.

  2. Do a search for all directories named helloworld and rename them to helloworld2.

  3. Search again for all files containing the text helloworld and edit these files to replace this text with helloworld2.

  4. Using a text editor, open the file jersey/samples/helloworld2/src/main/java/com/sun/jersey/samples/helloworld/resources/HelloWorldResource.java.

  5. Modify the text that is returned by the resource to Hello World 2. Save and close the file.

  6. Use Maven to compile and deploy the application. For this sample application, it is deployed onto Grizzly. Enter the following command from the command line to compile and deploy the application: mvn compile exec:java.

  7. Open a web browser, and enter the URL to which the application was deployed, which in this examples is http://localhost:9998/helloworld2. Hello World 2 will display in the browser.

See Also

You can learn more about deploying and running Jersey applications by reviewing the many sample applications that ship with Jersey. There is a README.html file for each sample that describes the sample and describes how to deploy and test the sample, and there is a Project Object Model file, pom.xml, that is used by Maven to build the project. Find a project that is similar to one you are hoping to create and use it as a template to get you started.

An example that starts from scratch can be found here.

For questions regarding Jersey sample applications, visit the Jersey Community Wiki page, or send an email to the users mailing list, users@jersey.dev.java.net.