Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to provide a java REST client, which should contain all required jars in one bundle. I chose RestEasy as REST framwork, since the server application is done on a JBoss.

Nearly all examples I found so far use either an application container environment, where those libs are provided and thus only the Java EE API is needed during compile or are build with Maven and thus dependencies are resolved automatically, which maybe be a good idea and the current standard way to do it, but for project-related reasons I need the jars in a lib folder and be able to include during the build and wihtin an executable jar.

So my question is, which jars a necessary to build a simple client which can do something like that:

ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(myURL).queryParam("param",
                "value");
Builder builder = target.request(MediaType.APPLICATION_JSON).header("user", "abc");
Invocation invocation = builder.buildGet();
MyResponseObject response = invocation.invoke(MyResponseObject .class);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
165 views
Welcome To Ask or Share your Answers For Others

1 Answer

The easiest way is to use Maven. The reason I say this, is that the main artifact you want is the resteasy-client artifact, but this artifact has dependencies on other artifacts. If I create a new Maven project, add only this dependency

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.9.Final</version>
</dependency>

The project will pull in all this artifacts

enter image description here

But if you are not using Maven, You can download the entire resteasy package here. It comes with a lot more than what you'll need, but it will have all the jars you see in the image above, along with some other goodies like user guides, examples and such. Base on the image above, just get the jars you need. Make sure you download the final-all version. When you unzip it, all the jars should be in the lib dir.

Another thing I might mention is that in order to unmarshal JSON representation into your Java classes, you might also need resteasy-jackson2-provider. Doing the same as above, you will see these pulled in artifacts

enter image description here

Again, these are also include in the download. This will work in most cases, if you are using JAXB annotations (which could return XML or JSON), because of the pulled in artifact jackson-module-jaxb-annotations, but that artifact doesn't support all JAXB annotations, so you might need to pull in the resteasy-jaxb-provider, if need be. Again like I said, just the jackson2-provider may be enough. But in the case you do need the jaxb-prodiver, here's what it looks like

enter image description here

Again, included in the download


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...