JAX-RS client Jersey Framework required jars

2019-09-12 15:36发布

问题:

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:

Jersey 2.x (2.22.1)

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

Jersey 1.x (1.19)

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

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>

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:

  • Documentation for 2.x client
  • Documentation for 1.x client