JAX-RS client Jersey Framework required jars

こ雲淡風輕ζ 提交于 2020-01-07 03:34:08

问题


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


来源:https://stackoverflow.com/questions/34792326/jax-rs-client-jersey-framework-required-jars

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