Maven provides apache cxf plugin to generate web service client.
We have used below code in our pom.xml file to generate java artifact classes (web service client).
There are two ways to generate client code:
Using complete WSDL URL
Using WSDL artifact
1. Using complete WSDL URL
Add plugin to your pom.xml file:
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf.version}</version> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>type your wsd url here </wsdl> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin>
sourceRoot is the location where generated classes are placed. We used ${project.build.directory}/generated/cxf location to place our client code.
2. Using WSDL artifactÂ
It will point to your directory where your web service code is available. In your pom.xml, replace your WSDL options tag with below code:
<wsdlOptions> <wsdlOption> <wsdlArtifact> <groupId>Enter groupId </groupId> <artifactId>Enter artifactid </artifactId> <version>specify version here</version> </wsdlArtifact> </wsdlOption> <wsdlOptions>
In this case, it will pick the WSDL available at the specified location inside maven repository and generate client code respectively.