...
Code Block | ||||
---|---|---|---|---|
| ||||
...
<configuration>
<sourceRoot>${project.build.directory}/generated-code/mywebservice</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl>
<!-- you can set the options of wsdl2java command by using the <extraargs> -->
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-verbose</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
...
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl> <bindingFiles> <bindingFile>${basedir}/src/main/resources/async_binding.xml</bindingFile>xml</bindingFile> </bindingFiles> </wsdlOption> </wsdlOptions> </configuration> |
In this example we're specifying that we want CXF to use our JAX-WS binding file. Binding files are a way to customize the output of the artifacts that CXF generates. For instance, it allows you to change the package name CXF uses.
Example 2: Specify the data binding
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl> <extraargs> <extraarg>-databinding</extraarg> <extraarg>jibx</extraarg> </bindingFiles>extraargs> </wsdlOption> </wsdlOptions> </configuration> |
In this example we're specifying that we want CXF to use our JAX-WS data binding file. Binding files are a way to customize the output of the artifacts that CXF generates. For instance, it allows you to change the package name CXF uses.
...
jibx. You can also using the data binding of xmlbeans, domsources, sdo etc.
Example 3: Specifying a service to generate artifacts for
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl> <serviceName>MyWSDLService</serviceName> </wsdlOption> </wsdlOptions> </configuration> |
...
To avoid copy/paste in multiple <wsdlOption> you can also declare a <defaultOption> element.
Example
...
4: Using defaultOption to avoid repetition
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <defaultOptions> <bindingFiles> <bindingFile>${basedir}/src/main/jaxb/bindings.xml</bindingFile> </bindingFiles> <noAddressBinding>true</noAddressBinding> </defaultOptions> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl> <serviceName>MyWSDLService</serviceName> </wsdlOption> <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/myOtherService.wsdl</wsdl> <serviceName>MyOtherWSDLService</serviceName> </wsdlOption> </wsdlOptions> </configuration> |
...
At least, you can declare a common wsdlRoot folder where you store your WSDL files and use includes/excludes patterns to select the files to get used by the code generator
Example
...
5: Using wsdlRoot with includes/excludes patterns
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <defaultOptions> <bindingFiles> <bindingFile>${basedir}/src/main/jaxb/bindings.xml</bindingFile> </bindingFiles> <noAddressBinding>true</noAddressBinding> </defaultOptions> <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot> <includes> <include>*Service.wsdl</include> </includes> </configuration> |
wsdlRoot default value is src/main/resources/wsdl
so you may omit this declaration.
Example
...
6: Loading a wsdl from the maven repository
For CXF 2.3 and latter there is a new config element <wsdlArtifact> which can be used to load a wsdl file from the maven repository.
...
This will load the wsdl /org/apache/pizza/PizzaService-1.0.0.wsdl into your local maven repository and generate java code from it.
Example
...
7: Using xjc extensions
Standard JAXB command-line customizations can be added via <extraarg> elements, either one per line or comma separated. CXF also offers some JAXB extensions for the code generation. They have to be added as dependencies and then activated by using an extraarg with content -xjc-X<extension id>
...
Code Block | ||||
---|---|---|---|---|
| ||||
<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> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl> <extraargs> <extraarg>-xjc-b,binding.xjb</extraarg> <extraarg>-xjc-Xts</extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-xjc-ts</artifactId> <version>${cxf.version}</version> </dependency> </dependencies> </plugin> |
Example
...
8 - Using JAXB/JAX-WS 2.2 with Java 6
Java 6 includes JAXB/JAX-WS 2.1 API's and a 2.1 implementations. However, sometimes it's desirable to use JAXB or JAX-WS 2.2 instead to obtain various bug fixes and enhancements. Using 2.2 with Java 6 and Maven can be a bit tricky as it requires endorsing the API jars which requires configuration of a bunch of plugins, requires use of "forking", etc... First off, both Surefire and the Compiler plugins need to be setup to point at an endorsed dir:
...