How to add JSR-311 dependency for Javen-RS maven project in Jersey

The following questions discuss the dependency theory between Jersey and the JAX-RS specification:

I assumed I could add a dependency:

<!-- javax.ws.rs.core eg Request --> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>1.0</version> </dependency> 

for my maven project defining API and use jersey / grizzly for implementation.

  <jersey.version>1.15</jersey.version> <grizzly.version>2.2.20</grizzly.version> 

In contrast to this assumption, I received the following error message:

 15.02.2013 08:41:25 org.glassfish.grizzly.http.server.HttpServerFilter handleRead WARNUNG: Unexpected error java.lang.IncompatibleClassChangeError: Class javax.ws.rs.core.Response$Status does not implement the requested interface javax.ws.rs.core.Response$StatusType at com.sun.jersey.spi.container.ContainerResponse.getStatus(ContainerResponse.java:571) 

What is the correct JAX-RS API dependency to be used with Jersey 1.15?

I would like to do this so that the implementation can be replaced with any other JAX-RS compatible library.

+4
source share
2 answers

The problem is that your JSR 311 API is version 1.0 dependent, while Jersey 1.15 is an implementation of JSR 311 version 1.1. Compare http://jsr311.java.net/nonav/releases/1.0/javax/ws/rs/core/Response.Status.html and http://jsr311.java.net/nonav/releases/1.1/javax/ws /rs/core/Response.Status.html , and you will see that the latter implements the ResponseType interface, but the former does not.

You must have JSR 311 API class files version 1.1.1 in the assembly class path, declaring something like this:

 <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> 

In fact, the pom.xml jersey core pom.xml already doing this - the above is just the first dependency at http://repo1.maven.org/maven2/com/sun/jersey/jersey-core/1.15/jersey-core-1.15.pom .

In a container like Glassfish, you have to do this, as the container will be responsible for providing the API classes for you at runtime (therefore, the scope in the Maven POM shirt is provided , not compile ). However, for the Grizzly web container, most likely you will need to make sure that the API classes are available at runtime (using the <dependency> declaration above, but changing the <scope> from provided to compile will do this).

+5
source

Well, if you just use knitwear, you are commenting your code with standard annotation like

 import javax.ws.rs.Path; 

The class is really provided by jersey jars. However, since this is the standard name for annotation, removing the jersey dependency, and using a different implementation of JSR-311, you MAY make it work without too much trouble. But it looks better in theory than in practice, in my opinion. Such things rarely go as smoothly as expected.

So, I am afraid that there is no satisfactory answer to your question (but I would be glad to make a mistake) ...

-1
source

All Articles