简体   繁体   中英

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

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.

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!

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

2) Back to the Maven dependencies;

Here I found:

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:

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.me defined in:

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.

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM