...
To use CXF within Maven, you'll need to declare the CXF dependencies in your POM. The CXF groupId is "org.apache.cxf". Here is a small example:
Code Block | ||||
---|---|---|---|---|
| ||||
<properties> <cxf.version>2.1.4</cxf.version> <properties> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>2.0.9<<version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>2.0.9<<version>${cxf.version}</version> </dependency> <!-- Jetty is needed if you're are not using the CXFServlet --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>2.0.9<<version>${cxf.version}</version> </dependency> </dependencies> |
...
Code Block | ||||
---|---|---|---|---|
| ||||
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>2.0.9<<version>${cxf.version}</version> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${basedir}/targetproject.build.directory}/generated/srccxf</main/java</sourceRoot>sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> |
...
Other configuration arguments can be include inside the <wsdlOption> element. These pass arguments to the tooling and correspond to the options outlined on the WSDL To Java page.
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.
Example 1: Passing in a JAX-WS Binding file
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <sourceRoot>${basedir}/target/generated/src/main/java<cxf</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl> <extraargs><bindingFiles> <extraarg>-b</extraarg> <extraarg>$<bindingFile>${basedir}/src/main/resources/wsdl/async_binding.xml</extraarg>bindingFile> </extraargs>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> <extraargs> <serviceName>MyWSDLService</serviceName> </wsdlOption> </wsdlOptions> </configuration> |
In this example we're specifying that we only want to generate artifacts for the service named "MyWSDLService" in the WSDL.
To avoid copy/paste in multiple <wsdlOption> you can also declare a <defaultOption> element.
Example 3: Using defaultOption to avoid repetition
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration> <sourceRoot>${basedir}/target/generated/cxf</sourceRoot> <wsdlOptions> <defaultOptions> <bindingFiles> <bindingFile>${basedir}/src/main/jaxb/bindings.xml</bindingFile> </bindingFiles> <noAddressBinding>true</noAddressBinding> </defaultOptions> <wsdlOption> <extraarg>-sn</extraarg> <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl> <extraarg>MyWSDLService<<serviceName>MyWSDLService</extraarg>serviceName> </extraargs>/wsdlOption> <wsdlOption> <wsdl>${basedir}/src/main/wsdl/myOtherService.wsdl</wsdl> <serviceName>MyOtherWSDLService</serviceName> </wsdlOption> </wsdlOptions> </configuration> |
<defaultOption> and <wsdlOption> correspond to the options outlined on the WSDL To Java page, you may look at http://svn.apache.org/repos/asf/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java for a more detailled description of thoses parameters.
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 4: Using wsdlRoot with includes/excludes patterns
Code Block | ||||
---|---|---|---|---|
| ||||
<configuration>
<sourceRoot>${basedir}/target/generated/cxf</sourceRoot>
<wsdlOptions>
<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>
</wsdlOptions>
</configuration>
|
wsdlRoot default value is src/main/resources/wsdl
so you may omit this declarationIn this example we're specifying that we only want to generate artifacts for the service named "MyWSDLService" in the WSDL.
Java2WSDL (CXF 2.0.x only. Removed in 2.1 and replaced with Java2WS.)
...