How do you include JAX-RS with Jersey in Maven?

一曲冷凌霜 提交于 2019-12-12 04:45:53

问题


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

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

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


回答1:


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

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.

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>

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




回答2:


please try as following:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version>
    <scope>compile</scope>
</dependency>



回答3:


Ended up finding a similar question here.

Solved the problem by manually adding the dependency under pom.xml:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>



回答4:


foun it on : (http://mvnrepository.com/artifact/org.glassfish.jersey.archetypes/project/2.22.1) it will work 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>


来源:https://stackoverflow.com/questions/25612117/how-do-you-include-jax-rs-with-jersey-in-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!