JAX-RS client Jersey Framework required jars

2019-09-12 15:18发布

What minimum JAR files of Jersey Framework are needed to run a client? If I include all JAR's it will take 4 MB.

1条回答
姐就是有狂的资本
2楼-- · 2019-09-12 16:14

Jersey 2.x (2.22.1)

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.22.1</version>
</dependency>

enter image description here

Jersey 1.x (1.19)

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.19</version>
</dependency>

enter image description here

Note: These are just the base client jars. There is no JSON support.

For JSON support, you can add these

<dependency>
    <groupId>com.fasterxml.jackson.jaxrs</groupId>
    <artifactId>jackson-jaxrs-json-provider</artifactId>
    <version>2.6.3</version>
</dependency>

enter image description here

For Jersey 2, you can register the JacksonJaxbJsonProvider

Client client = ClientBuilder.newClient();
client.register(JacskonJaxbJsonProvider.class);

For Jersey 1, you can do

ClientConfig config = new DefaultClientConfig();
config.getClasses().add(JacksonJaxbJsonProvider.class);
Client client = Client.create(config);

See Also:

查看更多
登录 后发表回答