【发布时间】:2014-09-01 19:44:08
【问题描述】:
我正在关注有关如何使用 JAX-RS 创建 RESTful Web 应用程序的 Vogella 教程。
我的麻烦是我无法通过 Maven 导入依赖项。有可能吗?
当我按照here 的建议尝试查找jsr311 或javax.ws.rs 时,Maven 似乎并不知道它的存在。
【问题讨论】:
我正在关注有关如何使用 JAX-RS 创建 RESTful Web 应用程序的 Vogella 教程。
我的麻烦是我无法通过 Maven 导入依赖项。有可能吗?
当我按照here 的建议尝试查找jsr311 或javax.ws.rs 时,Maven 似乎并不知道它的存在。
【问题讨论】:
如果您从头开始编写项目,最好让 maven 使用 Jersey 提供的 Maven Archetypes 之一为您生成项目(更多内容见Jersey getting-started page) 然后您可以使用以下命令轻松地将 Eclipse 性质添加到生成的项目中:
mvn eclipse:eclipse -Dwtpversion=2.0
选择您合适的 Web 工具版本,然后将该项目导入您的 Eclipse IDE。 此方法将使您无需提供与 Jersey 相关的任何依赖项,因为原型描述符中已经提到了这些依赖项。
否则,如果您已经在做一个项目并且想要添加 RESTful 功能(假设不正确,因为您提到您正在学习教程),您将必须提供对 Jersey你自己。所有依赖项都可以在in Maven Central Repo 找到,但您只需要jersey-server 一个:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.1</version>
</dependency>
正如@Gimby 所说,单独声明jsr311-api 绝对没有意义,只有当您打算提供JSR 实现时:)
【讨论】:
请尝试以下方法:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
【讨论】:
最终找到了一个类似的问题here。
通过在pom.xml下手动添加依赖解决了问题:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
【讨论】:
找到它:(http://mvnrepository.com/artifact/org.glassfish.jersey.archetypes/project/2.22.1) 它会工作 inchalahh ;D
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.1</version>
</dependency>
【讨论】: