I have to generate a WS Client and I can't decide wich plugin to use. Until now my options are: jaxb2-maven-plugin, axistools-maven-plugin and jaxws-maven-plugin.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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.
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.
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.