This section gives a simple introduction to using Jersey in NetBeans.
This section describes, using a very simple example, how to create a Jersey-annotated web application.
Before you can deploy a Jersey application using NetBeans, you must have installed the RESTful Web Services plugin, as described in Installing Jersey in NetBeans.
In NetBeans IDE, create a simple web application. For this example, we will work with a very simple “Hello, World” web application.
The project will be created. The file index.jsp will display in the Source pane.
Right-click the project and select New, then select RESTful Web Services from Patterns.
Select Singleton to use as a design pattern. Click Next.
Enter a Resource Package name, like HelloWorldResource. For MIME Type select text/html.
Enter /helloworld in the Path field. Enter HelloWorld in the Resource Name field.
Click Finish.
A new resource, HelloWorldResource.java, is added to the project and displays in the Source pane.
In HelloWorldResource.java, modify or add code to resemble the following example.
/** * Retrieves representation of an instance of helloworld.HellowWorldResource * @return an instance of java.lang.String */ @GET @Produces("text/html") public String getXml() { return "<html><body><h1>Hello World!</body></h1></html>"; } /** * PUT method for updating or creating an instance of HelloWorldResource * @param content representation for the resource * @return an HTTP response with content of the updated or created resource. */ @PUT @Consumes("application/xml") public void putXml(String content) { }
This section describes building, deploying, and testing a Jersey-annotated application using NetBeans IDE.
Right-click the project node and click Test RESTful Web Services.
This step will deploy the application and bring up a test client in the browser.
When the test client displays, navigate to the helloworld resource and click the Test button.
The words Hello World! will display in the Response window.
For other sample applications that demonstrate deploying and running Jersey applications using NetBeans, read Building and Running the HelloWorld-WebApp Application in NetBeans, Building and Running the Bookstore Application from NetBeans IDE, or look at the tutorials on the NetBeans tutorial site, such as the one titled Getting Started with RESTful Web Services: NetBeans 6.5. This tutorial includes a section on creating a CRUD application from a database.