Rest – When to use to create RESTful web services


I have developed RESTful web services in two ways:

  1. used a class that extends without defining a web.xml file, using Glassfish.

  2. haven't used but included a web.xml and a Jersey implementation, using Tomcat.

Is there a preferred way of building RESTful web services with JAX-RS?

Best Solution

Using the class is the preferred way and also the only portable way of configuring resources and providers in a JAX-RS web service, so if possible that would be the recommended way to set it up.

But that works well only in JAX-RS aware servlet containers or application servers, for JAX-RS non aware servers you need other ways for deployment and that most of the times means some proprietary servlet class of the JAX-RS implementation you are using.

To get more details on the subject, see for example the Jersey documentation, Deploying a RESTful Web Service (for Jersey v1.x) and Application Deployment and Runtime Environments (for Jersey v2.x).

Related Question