如何为Jersey Jax-RS Maven项目添加JSR-311依赖项 [英] How to add JSR-311 dependency for Jersey Jax-RS maven project

查看:395
本文介绍了如何为Jersey Jax-RS Maven项目添加JSR-311依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下问题讨论了Jersey和JAX-RS规范之间的依赖关系理论:

The following questions discusses the theory of the dependencies between Jersey and the JAX-RS specification:

我以为我可以添加依赖项:

I was assuming that I could add the dependency:

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

使用我的API定义maven项目,并使用Jersey/Grizzly进行实施.

to my API defining maven project and use Jersey/Grizzly for the implementation.

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

与此假设相反,我收到以下错误消息:

Contrary to this assumption I got 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)

应该与Jersey 1.15一起使用的正确的JAX-RS API依赖关系是什么?

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

我想以一种可以用其他兼容JAX-RS的库代替该实现的方式来实现.

I'd like to do it in a way that the implementation could be replaced by any other JAX-RS compliant library.

推荐答案

问题是您的JSR 311 API依赖项是1.0版,而Jersey 1.15是JSR 311的1.1版实现.比较 http://jsr311.java.net/nonav/releases /1.0/javax/ws/rs/core/Response.Status.html

The problem is your JSR 311 API dependency is version 1.0, whereas Jersey 1.15 is a JSR 311 version 1.1 implementation. 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.

通过声明以下内容,您应该能够在构建时类路径上拥有JSR 311版本1.1.1 API类文件:

You should be able to have the JSR 311 version 1.1.1 API class files on the build-time classpath by declaring something like this:

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

事实上,球衣核心pom.xml已经做到了-上面只是

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

在类似Glassfish的容器中,您现在已经完成了,因为该容器将负责在运行时为您提供API类(这就是为什么球衣自己的Maven POM的作用域为provided而不是).但是,对于Grizzly Web容器,可能需要确保API类在运行时可用(通过使用上面的<dependency>声明,但是将<scope>provided更改为compile是可以的)这个).

In a container like Glassfish, you'd now be done, since the container would be responsible for providing the API classes for you at runtime (which is why the scope in jersey's own Maven POM is provided, not compile). However, for the Grizzly web container, it is likely you'll need to ensure that the API classes are available at runtime (by using the <dependency> declaration above, but changing <scope> from provided to compile will do this).

这篇关于如何为Jersey Jax-RS Maven项目添加JSR-311依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆