您如何在Maven中将JAX-RS包含在Jersey中? [英] How do you include JAX-RS with Jersey in Maven?

查看:165
本文介绍了您如何在Maven中将JAX-RS包含在Jersey中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注有关Vogella的教程,该教程介绍了如何与JAX-RS一起使用以创建RESTful Web应用程序.

I'm following a tutorial on Vogella on how to work with JAX-RS to create RESTful web applications.

给我带来的麻烦是我无法通过Maven导入依赖项.有可能吗?

The trouble for me is that I am not able to import the dependencies through Maven. Is it possible?

当我尝试按照建议在这里找到jsr311javax.ws.rs时,Maven似乎不知道存在.

When I try finding jsr311 or javax.ws.rs as suggested here, Maven doesn't seem to know it exists.

推荐答案

如果您是从头开始制作项目,最好让maven使用 Maven原型之一为您生成项目 Jersey 提供的内容( Jersey入门中的更多内容页),则可以使用以下命令轻松地将Eclipse自然添加到生成的项目中:

If you are satrting your project from scratch, it would be better to let maven generate your project for your using one of the Maven Archetypes that Jersey provides (More in the Jersey getting-started page) then you can easilly add the eclipse nature to the generated project using below command:

mvn eclipse:eclipse -Dwtpversion=2.0

选择合适的Web工具版本,然后将该项目导入到 Eclipse IDE 中. 此方法将使您摆脱与 Jersey 相关的任何依赖关系的模棱两可,就像原型描述符中已经提到的那样.

Choose your suitable Web Tool version, then import that project into your Eclipse IDE. This method, will leave you out of poviding any dependencies related to Jersey as those are already mentioned in the archetype descriptor.

否则,如果您已经在开发项目,并且想要添加RESTful功能(由于您提到正在学习教程,因此假设不正确),则必须为 Jersey <提供依赖关系. /em>自己.可以在Maven Central Repo中 中找到所有依赖项,但您只需要jersey-server一个:

Otherwise, if you are already working on a project and you want to add the RESTful features (which assume is not true since you mentioned that you are following a tutorial), you will have to provide dependencies to Jersey yourself. All dependencies can be found in Maven Central Repo but you would only need the jersey-server one:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.18.1</version>
</dependency>

如@Gimby所述,仅当您打算提供JSR实现时,单独声明jsr311-api绝对没有任何意义:)

As @Gimby stated, there is absolutely no sense in declareing the jsr311-api alone, only if you are intending to provide a JSR implementation :)

这篇关于您如何在Maven中将JAX-RS包含在Jersey中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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