Java REST API 的 Maven 依赖项 - Jersey - Glassfish 与否?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19060298/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:46:32  来源:igfitidea点击:

Maven dependencies for REST API - Jersey - Glassfish or not?

javarestmavenglassfishjersey

提问by blueSky

I'm new to REST API and little familiar with Maven. I noticed that most people use REST with Jersey implementation. I need to write POST requests and might also need GET requests as well. I have difficulty finding out the right - minimum required - dependencies for Maven to start coding.

我是 REST API 的新手,对 Maven 不太熟悉。我注意到大多数人将 REST 与 Jersey 实现一起使用。我需要编写 POST 请求,也可能还需要 GET 请求。我很难找到正确的 - 最低要求 - Maven 开始编码的依赖项。

I looked at many resources online. Looks like Jersey comes with Glassfish Server. I have Tomcat installed on my local PC which I'm going to use for development of REST and testing. We have Jboss running on our production servers which my code eventually will be deployed to. It looks to me that different resources say different things or there are chances I'm not getting it!

我在网上看了很多资源。看起来 Jersey 带有 Glassfish Server。我在本地 PC 上安装了 Tomcat,我将用它来开发 REST 和测试。我们在生产服务器上运行 Jboss,我的代码最终将部署到这些服务器上。在我看来,不同的资源说的是不同的东西,或者我有可能没有得到它!

1) Can I use Jersey with Tomcat or Jboss WITHOUT any dependency on Glassfish?

1) 我可以在不依赖 Glassfish 的情况下将 Jersey 与 Tomcat 或 Jboss 一起使用吗?

2) Back to the Maven dependencies;

2)回到Maven依赖;

Here I found:

在这里我发现:

http://aike.me/site/blog/20090914/restful_web-services_in_java_using_jax-rs_-_part_1_getting_up_and_running

http://aike.me/site/blog/20090914/restful_web-services_in_java_using_jax-rs_-_part_1_getting_up_and_running

Maven: Getting Jersey into your project

<repositories>
    <repository>
        <id>maven2-repository.dev.java.net</id>
        <name>Java.net Repository for Maven</name>
        <url>http://download.java.net/maven/2/</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.0.3.1</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.1.12</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.0</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1</version>
    <scope>provided</scope>
</dependency>

Are these would be ALL I need?

这些就是我所需要的吗?

B/c in Jersey website I found different dependencies defined:

在 Jersey 网站的 B/c 我发现定义了不同的依赖项:

https://jersey.java.net/documentation/latest/modules-and-dependencies.html

https://jersey.java.net/documentation/latest/modules-and-dependencies.html

I won't copy and paste those dependencies here b/c it makes this post very long. I do NOT see any of these dependencies - mentioned in http://aike.medefined in:

我不会在 b/c 中复制和粘贴这些依赖项,这会使这篇文章很长。我没有看到任何这些依赖项 - 在http://aike.me中提到:

https://jersey.java.net

https://jersey.java.net

Such as:

如:

<artifactId>jersey-server</artifactId>

<artifactId>jaxb-impl</artifactId>

<artifactId>jsr311-api</artifactId>

<artifactId>jaxb-api</artifactId>

Why is that? Why I'm being referred to different dependencies?

这是为什么?为什么我被称为不同的依赖项?

Any help is greatly appreciated.

任何帮助是极大的赞赏。

采纳答案by Ryszard Grodzicki

Using a dependency with "org.glassfish.*" in group id doesn't mean you have to use Glassfish server.

在组 ID 中使用带有“org.glassfish.*”的依赖项并不意味着您必须使用 Glassfish 服务器。

Jersey has become a part of glassfish and that's the only reason the package name has changed. The newest versions are released under this package and it is recommended on the Jersey website so I would stick with the newest packages.

Jersey 已成为 glassfish 的一部分,这是包名称更改的唯一原因。最新版本是在这个包下发布的,它被推荐在 Jersey 网站上,所以我会坚持使用最新的包。

回答by Sagar

I have created a quick start template for the same, feel free to fork or clone it. Get it here

我已经为此创建了一个快速入门模板,请随意分叉或克隆它。 在这里获取