The JAX-RS 1.1 specification says on page 6:
If no Application subclass is present the added servlet MUST be named:
javax.ws.rs.core
There are a number of options for deploying into a Java EE 6 container (more specifically a Servlet 3.0 implementation):
The simplest is:
javax.ws.rs.core.Application
1
javax.ws.rs.core.Application
/rest/*
Then all the @Path
and @Provider
classes found in your web application will be available in the "default" JAX-RS application with a servlet URL pattern of "/rest/*"
.
If you have one or more classes that extends javax.ws.rs.core.Application
, you can specify like so:
com.example.jaxrs.MyApplication
1
com.example.jaxrs.MyApplication
/rest/*
You may want to do the above in case you wish to only return specific sets of @Path
/@Provider
classes on a URL (so you could have a second MyApplication2 with a different URL pattern above).
You can also skip the whole web.xml
altogether and just annotate your MyApplication
class wih @ApplicationPath
which will serve as the URL pattern. I would recommend keeping the web.xml
in any case because you will probably have to add other information about the web application there anyway.
If you're wondering where the servlet-class
comes from, it is automatically added in by the environment. You can get an idea by looking at the Servlet 3.0 ServletContext
.