I do not think that the answers given are the best for the initial statement of the problem.
He wants to have his sub-resources in separate classes. This is understandable and admirable, because not doing it would mean putting all its endpoints in one class, which would be huge.
If all the endpoints on this port start with /app , then I think the best way to do this is to configure your filter to fit in your @ApplicationPath .
If this is not the case when all endpoints start with the same prefix, you will have to use this JAX-RS subresource style, where you specify @Path but not the HTTP method annotation ( @GET , etc.) And return instance of the resource you want to delegate:
@Path("/app") public class AppResource { @Context UriInfo uriInfo; @Path("fizz") public FizzResource getItemContentResource() { return new FizzResource (); } } @Produces(MediaType.APPLICATION_JSON) public class FizzResource extends AppResource {
This use of resources is provided in the JAX-RS documentation .
You can also have all your subresources declare their paths as
@Path(BASE_URL + "/fizz")
Where BASE_URL is a static string, but I would try to avoid this, because using a not-so-constant parameter for @Path seems to cause problems for every JAX-RS IDE plugin I came across. They cannot figure out the actual path, so they give up. Thus, you may lose the ability to have a “JAX-RS view” that allows you to visualize / move JAX-RS resources along paths.
source share