java - 修改从 wsdl 生成的 java 类的包名

标签 java wsdl

如何修改从多个 wsdls 生成的 java 类的包名称。我有两个 wsdls,它们都在生成 ObjectFactory、package-info 等具有完全相同的包名称的类。因此,我无法在我的代码中组织导入。我的 wsdls 包看起来像这样 -

WSDL A
    com.test.customerinfo.dto
    com.test.customerinfo.exceptions
    com.test.customerinfo.service

WSDL B    
    com.test.customerinfo.dto
    com.test.customerinfo.exceptions
    com.test.customerinfo.service

我希望它看起来像这样 -

WSDL A
    com.test.customerinfo.dto
    com.test.customerinfo.exceptions
    com.test.customerinfo.service

WSDL B    
    com.testOne.customerinfo.dto
    com.testOne.customerinfo.exceptions
    com.testOne.customerinfo.service

我试过了,但是没用-

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>2.7.7</version>
    <executions>
       <execution>
          <id>generate-sources</id>
          <phase>generate-sources</phase>
          <configuration>
             <sourceRoot>target/generated-sources/test/java</sourceRoot>
             <wsdlOptions>
                <wsdlOption>
                   <wsdl>src/main/resources/wsdl/test/GetInfo.wsdl</wsdl>
                   <extraargs>
                      <extraarg>-server</extraarg>
                      <extraarg>-client</extraarg>
                      <extraarg>-impl</extraarg>
                      <extraarg>-verbose</extraarg>
                      <extraarg>-p</extraarg>
                      <extraarg>http://dto.customerinfo.test.com/=com.test.customerinfo.dto</extraarg>
                      <extraarg>-p</extraarg>
                      <extraarg>http://services.customerinfo.test.com/=com.test.customerinfo.services</extraarg>
                      <extraarg>-p</extraarg>
                      <extraarg>http://exceptions.customerinfo.test.com/=com.test.customerinfo.exceptions</extraarg>
                   </extraargs>
                   <frontEnd>jaxws21</frontEnd>
                   <faultSerialVersionUID>1</faultSerialVersionUID>
                </wsdlOption>
             </wsdlOptions>
          </configuration>
          <goals>
             <goal>wsdl2java</goal>
          </goals>
       </execution>
    </executions>
 </plugin>

请指教。

最佳答案

cxf-codgen-plugin 中,您可以在 wsdlOptions 部分指定包映射:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            ...
            <configuration>
                ...
                <wsdlOptions>
                    <wsdlOption>
                        ...
                        <packagenames>
                        <!-- Package Mappings -->
                            <packagename>http://namespace.example.com/=com.test.package</packagename>
                        </packagenames>
                        ...
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

或者你也可以使用extraarg:

<wsdlOptions>
    <wsdlOption>
        ...
        <extraargs>
            <extraarg>-p</extraarg>
            <extraarg>http://namespace.example.com/=com.test.package</extraarg>
        </extraargs>
    </wsdlOption>
</wsdlOptions>

关于java - 修改从 wsdl 生成的 java 类的包名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27717660/

相关文章:

java - Apache Spark : TaskResultLost (result lost from block manager) Error On cluster

java - Java Duration 的最大值是多少

Ruby 和 Savon 错误 : POST method not supported by this URL

.NET 5.0 和 SOAP Web 服务

asp.net - 从 wsdl 生成 Web 服务

将 WSDL 中定义的响应反序列化为空消息时,WCF 使用 SOAP 会出错

java - Windows cmd通信的实现方法——多条命令

java - 为什么我的 SQLite 数据库操作 "updateinformation2"没有更改我的 "name"值?

Java 生成 WSDL 但无法使用 ?wsdl 访问它

java - 用于渲染 JSON 的 Spring 模板引擎