java RestEasy 客户端所需的 jars

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26677489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:22:53  来源:igfitidea点击:

Required jars for RestEasy Client

javarestjax-rsresteasyjava-ee-7

提问by Alexander Rühl

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.

我需要提供一个 java REST 客户端,它应该在一个包中包含所有必需的 jar。我选择 RestEasy 作为 REST 框架,因为服务器应用程序是在 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.

到目前为止,我发现的几乎所有示例都使用应用程序容器环境,其中提供了这些库,因此在编译期间只需要 Java EE API 或使用 Maven 构建,因此依赖项会自动解决,这可能是一个好主意,并且当前的标准方法,但出于与项目相关的原因,我需要 lib 文件夹中的 jar,并且能够在构建过程中包含一个可执行的 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);

回答by Paul Samsotha

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

最简单的方法是使用Maven。我这样说的原因是,您想要的主要工件是resteasy-client工件,但是此工件对其他工件具有依赖性。如果我创建一个新的 Maven 项目,只添加这个依赖项

<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 libdir.

但是如果你没有使用 Maven,你可以在这里下载整个 resteasy 包。它提供了比您需要的更多的东西,但它将包含您在上图中看到的所有罐子,以及其他一些好东西,如用户指南、示例等。根据上图,获取您需要的罐子。确保下载最终版本。当你解压它时,所有的罐子都应该在lib目录中。

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

我可能会提到的另一件事是,为了将 JSON 表示解组到 Java 类中,您可能还需要resteasy-Hymanson2-provider. 和上面一样,你会看到这些被拉入了工件

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 Hymanson-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 Hymanson2-provider may be enough. But in the case you doneed the jaxb-prodiver, here's what it looks like

同样,这些也包含在下载中。这在大多数情况下都有效,如果您使用 JAXB 注释(可能返回 XML 或 JSON),因为拉入了 artifact Hymanson-module-jaxb-annotations,但该 artifact 不支持所有 JAXB 注释,因此您可能需要拉入resteasy-jaxb-provider, 如果需要。再次像我说的那样,仅 Hymanson2-provider 可能就足够了。但如果你确实需要 jaxb-prodiver,它看起来像

enter image description here

在此处输入图片说明

Again, included in the download

再次,包含在下载中

回答by Tomasz Godziński

If you use maven in your project, you can type dependency:treeto see hierarchy of your dependencies. Libraries used by RestEasy will be listed in tree.

如果您在项目中使用 maven,则可以键入dependency:tree以查看依赖项的层次结构。RestEasy 使用的库将在树中列出。