RESTful Web Services Developer's Guide

ProcedureCreating a Jersey-Annotated Web Application using NetBeans IDE

This section describes, using a very simple example, how to create a Jersey-annotated web application.

Before You Begin

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.

  1. In NetBeans IDE, create a simple web application. For this example, we will work with a very simple “Hello, World” web application.

    1. Open NetBeans IDE.

    2. Select File->New Project.

    3. From Categories, select Java Web. From Projects, select Web Application. Click Next.

    4. Enter a project name, HelloWorldApp, click Next.

    5. Make sure the Server is GlassFish v3 Prelude.

    6. Click Finish.

  2. The project will be created. The file index.jsp will display in the Source pane.

  3. Right-click the project and select New, then select RESTful Web Services from Patterns.

    1. Select Singleton to use as a design pattern. Click Next.

    2. Enter a Resource Package name, like HelloWorldResource. For MIME Type select text/html.

    3. Enter /helloworld in the Path field. Enter HelloWorld in the Resource Name field.

    4. Click Finish.

      A new resource, HelloWorldResource.java, is added to the project and displays in the Source pane.

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