34.5. Java-to-WSDL Maven Plug-In
Overview
To generate a WSDL contract from your SEI, you can use either the
java2ws
command-line utility or the cxf-java2ws-plugin
Maven plug-in. The plug-in approach is ideal for Maven-based projects: after you paste the requisite plug-in configuration into your POM file, the WSDL code generation step is integrated into your build.
Configure the Java-to-WSDL Maven plug-in
Configuring the Java-to-WSDL Maven plug-in is relatively easy, because most of the default configuration settings can be left as they are. After copying and pasting the sample
plugin
element into your project's POM file, there are just a few basic settings that need to be customized, as follows:
- CXF version—make sure that the plug-in's dependencies are using the latest version of Apache CXF.
- SEI class name—specify the fully-qualified class name of the SEI in the
configuration/className
element. - Location of output—specify the location of the generated WSDL file in the
configuration/outputFile
element.
For example, the following POM fragment shows how to configure the
cxf-java2ws-plugin
plug-in to generate WSDL from the CustomerService SEI:
<project ...> ... <properties> <cxf.version>3.0.4.redhat-620133</cxf.version> </properties> <build> <defaultGoal>install</defaultGoal> <plugins> ... <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-java2ws-plugin</artifactId> <version>${cxf.version}</version> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-simple</artifactId> <version>${cxf.version}</version> </dependency> </dependencies> <executions> <execution> <id>process-classes</id> <phase>process-classes</phase> <configuration> <className>org.fusesource.demo.camelcxf.ws.server.CustomerService</className> <outputFile>${basedir}/../src/main/resources/wsdl/CustomerService.wsdl</outputFile> <genWsdl>true</genWsdl> <verbose>true</verbose> </configuration> <goals> <goal>java2ws</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Generated WSDL
When using the Java-first approach to defining a Web service, there are typically other parts of your application (for example, WS clients) that depend on the generated WSDL file. For this reason, it is generally a good idea to output the generated WSDL file to a common location, which is accessible to other projects in your application, using the
outputFile
configuration element.
If you do not specify the
outputFile
configuration element, the generated WSDL is sent to the following location, by default:
BaseDir/target/generated/wsdl/SEIClassName.wsdl
Reference
For full details of how to configure the Java-to-WSDL plug-in, see the Maven Java2WS plug-in reference page.