Packaging and deploying JAX-RS applications

There are multiple ways to configure, package, and deploy a JAX-RS application. While configuring an application, you can use an annotation-based approach (for the Servlet 3.x-based container) and thereby avoid deployment descriptors such as web.xml. Alternatively, you can use a mix of both approaches, which uses both annotations and web.xml. This section describes the various configurations and packaging models followed for a JAX-RS web service application.

The JAX-RS specification states that a RESTful web service must be packaged as part of a web application if you want to run it in a container (web server or application server). Following this rule, any JAX-RS application that you want to deploy on a server must be packaged in a Web Application Archive (WAR) file. If the web service is implemented using an EJB, it must be packaged and deployed within a WAR file. The application classes are packaged in WEB-INF/classes or WEB-INF/lib and all the dependent library JARs are packaged in WEB-INF/lib. You can configure a JAX-RS application in the following ways:

  • Using the javax.ws.rs.core.Application subclass without web.xml
  • Using the Application subclass and web.xml
  • Using web.xml without the Application subclass

Let's take a closer look at all these packaging models. The following discussion presumes the Jersey framework as the JAX-RS implementation. Though the basic packaging model is the same across all JAX-RS implementations, the exact value for certain metadata fields used in the deployment descriptors, such as the servlet class, may change with each implementation. Please refer to the product documentation if you are using a different JAX-RS implementation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.7.240