eclipse 你如何在 Maven 中包含 JAX-RS 和 Jersey?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25612117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you include JAX-RS with Jersey in Maven?
提问by CodyBugstein
I'm following a tutorial on Vogella on how to work with JAX-RS to create RESTful web applications.
我正在关注有关如何使用 JAX-RS 创建 RESTful Web 应用程序的 Vogella 教程。
The trouble for me is that I am not able to import the dependencies through Maven. Is it possible?
对我来说的麻烦是我无法通过 Maven 导入依赖项。是否可以?
When I try finding jsr311
or javax.ws.rs
as suggested here, Maven doesn't seem to know it exists.
当我尝试查找jsr311
或javax.ws.rs
按照此处的建议进行查找时,Maven 似乎不知道它存在。
回答by tmarwen
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 Archetypesthat Jerseyprovides (More in the Jersey getting-started page) then you can easilly add the eclipse nature to the generated project using below command:
如果您satrting从头开始你的项目,这将是更好地让行家生成项目您使用的一个Maven的原型是新泽西州提供了(多在新泽西州获得启动的页面),那么你可以easilly添加日食性质的使用以下命令生成项目:
mvn eclipse:eclipse -Dwtpversion=2.0
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 Jerseyas those are already mentioned in the archetype descriptor.
选择合适的 Web Tool 版本,然后将该项目导入Eclipse IDE。这种方法将使您无需提供与Jersey相关的任何依赖项,因为原型描述符中已经提到了这些依赖项。
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 Jerseyyourself. All dependencies can be found in Maven Central Repobut you would only need the jersey-server
one:
否则,如果您已经在处理一个项目并且想要添加 RESTful 功能(假设不是真的,因为您提到您正在学习教程),您将必须自己提供对Jersey 的依赖项。所有依赖项都可以在 Maven Central Repo 中找到,但您只需要jersey-server
一个:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.1</version>
</dependency>
As @Gimby stated, there is absolutely no sense in declareing the jsr311-api
alone, only if you are intending to provide a JSR implementation :)
正如@Gimby 所说,jsr311-api
仅当您打算提供 JSR 实现时,才单独声明绝对没有意义:)
回答by eGhoul
foun it on : (http://mvnrepository.com/artifact/org.glassfish.jersey.archetypes/project/2.22.1) it will work inchalahh ;D
在 : ( http://mvnrepository.com/artifact/org.glassfish.jersey.archetypes/project/2.22.1) 上找到它,它将起作用 inhalahh ;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>
回答by CodyBugstein
回答by Saeed Alizadeh
please try as following:
请尝试如下:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>