...
In this example we're running the wsdl2java goal in the generate-sources phase. By running mvn generate-sources, CXF will generate artifacts in the <sourceRoot> directory that you specify. Each <wsdlOption> element corresponds to a WSDL that you're generated artifacts for. In the above example we're generating we're specifying the WSDL location via the <wsdl> option.
The following example shows some customization options. A <sourceRoot> value can be added under the <configuration/> element if you wish to use something other than the Maven convention of "target/generated-sources/cxf" as the output folder for the generated artifacts (rarely necessary). Other configuration arguments can be included inside the <wsdlOption> element. These pass arguments to the tooling and correspond to the options outlined on the WSDL To Java page, for . For example:
Code Block |
---|
|
...
<configuration>
<sourceRoot>${project.build.directory}/generated/mywebservice</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-verbose</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
...
|
For CXF 2.1.4 and latter you don't need anymore to specify the <phase>, as generate-sources is the default.
For CXF 2.2 and latter you don't even need to specify the <sourceRoot> to match maven convention for using target/generated-sources/cxf as output folder for generated classes.
See this blog entry for a full service and client example that uses the cxf-codegen-plugin.
...
Code Block |
---|
|
<configuration>
<sourceRoot>${basedir}/target/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/async_binding.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
|
...
Code Block |
---|
|
<configuration>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
<serviceName>MyWSDLService</serviceName>
</wsdlOption>
</wsdlOptions>
</configuration>
|
...
Code Block |
---|
|
<configuration>
<sourceRoot>${basedir}/target/generated/cxf</sourceRoot>
<defaultOptions>
<bindingFiles>
<bindingFile>${basedir}/src/main/jaxb/bindings.xml</bindingFile>
</bindingFiles>
<noAddressBinding>true</noAddressBinding>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
<serviceName>MyWSDLService</serviceName>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myOtherService.wsdl</wsdl>
<serviceName>MyOtherWSDLService</serviceName>
</wsdlOption>
</wsdlOptions>
</configuration>
|
...
Code Block |
---|
|
<configuration>
<sourceRoot>${basedir}/target/generated/cxf</sourceRoot>
<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>
|
...
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>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/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>
|