0

My maven module pom.xml looks like

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <version>2.8</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.test.framework</groupId>
        <artifactId>jersey-test-framework</artifactId>
        <version>1.0.3.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

and a Resource class as

@Service
@Path("/hello")
public class HelloResource {

    @GET
    public Response hello() {
        return Response.ok("Hello World!").build();
    }
}

This all works fine.
Question
- I just saw this post, which says

You need both the JSR and the implementation. The annotations are in the JSR, the implementation provides supporting classes

May I know the reason why this is needed?

Community
  • 1
  • 1
daydreamer
  • 87,243
  • 191
  • 450
  • 722

1 Answers1

1

The dependencies you have in there will retrieve, by Maven transitive dependency mechanism, the JSR API jar as well. So, if you are asking why that is working well, it is because jax.ws.rs-api 2.0 will be available through jersey-server -> jersey-common -> jax.ws.rs-api path.

If you're asking why both are needed (even by Maven transitive dependency mechanism), then I would believe that the reason is a separation between API and implementation. Your code depends at compile time on the JSR API, but at runtime it will need the implementation as well. So, theoretically, one can swap out one implementation with the other without affecting the code.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89