1
votes

I can't seem to get my jersey resources recognized in my app. According to everything I read online, there are two possible cases where this may happen.

  1. There is no valid package declared in the web.xml under com.sun.jersey.config.property.packages.

This is my web.xml:

<web-app version="3.0"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     metadata-complete="false">

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>
        com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>my.package</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

: 2. There is no valid resource class in my.package.

My resource class:

package my.package;

import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.core.Response;

@Path("/")
class MyClass{

@GET
public Response asdf(){
    return Response.ok().build();
}

@Path("/test")
@GET
public Response test(){
    return Response.ok().build();
}
}

As far as I can tell, neither of these two conditions are satisfied.

For the sake of completion, here are my dependencies:

<dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.17</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.17</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.17</version>
    </dependency>

Any ideas as to why I might be getting this error?

1

1 Answers

0
votes
@Path("/")
class MyClass{

The class isn't visible to Jersey. Try changing it to (note the addition of "public"):

@Path("/")
public class MyClass{