Using the javax.ws.rs.core.Application class is the preferred method, as well as the only portable way to configure resources and providers in the JAX-RS web service, so if possible, this would be the recommended way to configure it.
But this only works well in JAX-RS servlet containers, or on application servers, for unsecured JAX-RS servers you need other deployment methods, and that most of the time means some proprietary JAX-RS servlet class that you use.
For more information on this, see, for example, the Jersey documentation, Deploying the RESTful Web Service (for Jersey v1.x) and Deploying Applications and the Runtime (for Jersey v2.x).
source share