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) {
}