Total Pageviews

2019/07/05

[Maven] How to generate WSDL client code via Apache CXF in Maven?

Scenario


How-To
I have three WSDL files in my spring boot project:


Apache CXF includes a Maven plugin which can generate java artifacts from WSDL. Here is a simple example:
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.2.6</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- define location which CXF will generate artifacts -->
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <encoding>UTF-8</encoding>
                            <wsdlOptions>
                                <!-- generate io_ws wsdl client code to 
                                    test.ws.bind.oi2 package -->
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/oi_ws.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oi</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>

                                <!-- generate oe_ws wsdl client code to 
                                    test.ws.bind.oe package -->
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/oe_ws.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oe</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>

                                <!-- generate oj_ws wsdl client code to 
                                    test.ws.bind.oj package -->
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/oj_ws.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oj</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

After executing mvn clean install, you can find out artifacts in ${project.build.directory}/generated/cxf :


Reference
[1] http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html

No comments: