wulfgarpro wulfgarpro - 1 month ago 31
Java Question

Loading resources using Jersey and @ApplicationPath annotation

I'm trying to deploy a basic jersey restful service to Tomcat7 without web.xml:

public class MyResource extends Application {

public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
return s;

public String getWelcome(@PathParam(value = "name") String name) {
return "Welcome to jax-rs " + name;

I'm presented with a 404 when trying to access: /myapplication/resources/mypath/sample.

I can deploy a servlet using the
annotation, so this has nothing to do with the loading of servlets without web.xml into Tomcat7.

From reading the documentation for Jersey, the runtime should scan for classes extending
and execute
, loading all root resources.

Answer Source

Which version of Jersey are you using? Try splitting application and resource in two classes. Definitely remove @WebServlet annotation. I.e. have one class extending Application annotated with @ApplicationPath and another class annotated with @Path.

EDIT: Make sure that jersey-servlet.jar is included in your WAR file.