Total Pageviews

2019/08/05

[Maven] Fail to generate web client code by wsdl2java

Scenario


Problem 
When I try to generate web service client code from WSDL :
            <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>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/OQ2Info.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oq2</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


I will get exception after I execute mvn clean install :
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.2.6:wsdl2java (generate-sources) on project test: 
Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.2.6:wsdl2java failed: 
file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [32,7]: 相同名稱 "test.ws.bind.oq2.Exception" 的類別/介面已在使用中. 請使用類別自訂項目以解決此衝突.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [27,7]: (與上述錯誤有關) 另一個 "Exception" 從此處產生.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [32,7]: 兩個宣告導致 ObjectFactory 類別發生衝突.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [27,7]: (與上述錯誤有關) 此為另一個宣告.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [35,13]: 兩個宣告導致 ObjectFactory 類別發生衝突.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [29,11]: (與上述錯誤有關) 此為另一個宣告.
[ERROR]
[ERROR] -> [Help 1]



How-To
Owning to naming conflicts occur in this WSDL file, so I need to set autoNameResolution to true to resolve this problem:


            <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>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/OQ2Info.xml</wsdl>
                                    <autoNameResolution>true</autoNameResolution>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oq2</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>




No comments: