We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
首先,
jaxb2-maven-plugin
并不是真正旨在生成 WS 客户端。被淘汰了。其次,就个人而言即使仅用于客户端开发我也不会使用Axis所以我不建议使用
axistools-maven-plugin
。被淘汰了。这给我们留下了 JAX-WS RI 和 Apache CXF 堆栈,以及它们各自的 Maven 插件: JAX-WS Maven 插件(使用 JAX-WS Maven 插件的说明可以在 用法 页面)和 cxf-codegen-plugin。
关于优缺点,我会这样总结:
最后,这两个选择都不错,所以我建议稍微浏览一下链接并发表自己的意见。
First, the
jaxb2-maven-plugin
is not really intended to generate WS clients. ELIMINATED.Second, personally I wouldn't use Axis even for client development only so I won't recommend using the
axistools-maven-plugin
. ELIMINATED.This leaves us with the JAX-WS RI and the Apache CXF stacks, and their respective Maven plugins: the JAX-WS Maven Plugin (instructions to use the JAX-WS Maven Plugin can be found on the Usage page) and the cxf-codegen-plugin.
Regarding the pros and cons, I would summarize them like this:
At the end, both choices are decent so I suggest to browse the links a bit and to make your own opinion.
我使用 jaxws-maven-plugin。在我看来,JAX-WS 是 WS 事实上的标准实现。它具有比 AXIS 更好的生成代码,并且更易于配置和实施。它有 Maven 和 Spring 支持。
在 pom.xml 中从 wsdl 文件生成客户端代码:
用于创建客户端服务 bean 的接口(这不是自动生成的):
它的 Bean 实现:
这个 bean(用作 Spring bean)的想法是拥有一个单例用于生成客户服务代码。它需要两个输入: WSDL url - 即实现 WSDL 的服务器的实际 URL。客户端服务代码在构造时会向所提供的 URL 发送对 WSDL 的获取请求。然后,它根据自动生成的代码中的注释创建 WSDL,并进行比较。我相信这样做是为了确保您正在运行正确的服务器版本。
因此,我已将 url 放置在我的应用程序可访问的属性文件中,因此我在 Spring 应用程序上下文文件中进行初始化。
下面是使用工厂生成服务然后使用它的示例:
从这里开始,只需使用端口变量来调用 wsdl 上可用的任何操作。
I use jaxws-maven-plugin. In my opinion, JAX-WS is the de-facto standard implementation for WS. It has much better generated code than AXIS, and easier to config and implement. It has Maven and Spring support.
Generating client-side code from wsdl file, in pom.xml:
An interface to create the client service bean (this is not auto generated):
Its Bean implementation:
The idea in this bean (used as Spring bean) is to have a singleton for generating a client service code. It requires two inputs: The WSDL url - that is, the actual URL of the server which implements the WSDL. The client service code, upon construction, send a get request for the WSDL at the supplied URL. It then creates the WSDL based on the annotations residing in the auto generated code, and it compares it. I believe this is done to make sure you're running against the correct server version.
So, I've placed the url in a property file accessible to my application, thus I initialize in my Spring application context file.
Here's an example of using the factory to generate a service and then using it:
From here, just use the port variable to call any operation available on the wsdl.
所需的 Maven 插件:
JAX-WS 到 WSDL
通过使用“java2ws”目标配置 cxf-java2ws-plugin,从 JAX-WS 带注释的类生成 WSDL 文档。
添加 JAX-WS 带注释的类所需的 cxf-rt-frontend-jaxws 依赖项和项目依赖项作为插件依赖项。
WSDL 2 Java
通过使用“wsdl2java”目标配置 cxf-codegen-plugin,从 WSDL 文档生成 Java 客户端。
'-p' 参数指定包类。
生成的类将放置在 target/ generated-sources/cxf 文件夹中。
Maven plugins required:
JAX-WS to WSDL
To generate the WSDL document from the JAX-WS annotated class by configuring cxf-java2ws-plugin with the ‘java2ws’ goal.
Add the cxf-rt-frontend-jaxws dependency and project dependencies required for the JAX-WS annotated class as plugin dependencies.
WSDL 2 Java
To generate the Java client from the WSDL document by configuring cxf-codegen-plugin with ‘wsdl2java’ goal.
The ‘-p’ argument specifies the package classes .
The generated classes will be placed in the target/generated-sources/cxf folder.