如何在Pom.xml中从WSDL生成Java源代码?

时间:2011-02-28 09:36:44

标签: java wsdl pom.xml

我有一个pom文件,它从WSDL文件生成源代码,其设计类似于此。

    <executions>
        <execution>
        <id>Id1</id>
        <goals>
               <goal>wsimport</goal>
        </goals>
        <configuration>
            <wsdlLocation>wsdl/HelloService.wsdl</wsdlLocation>
         <wsdlFiles>
                <wsdlFile>HelloService.wsdl</wsdlFile>
        </wsdlFiles>
        <staleFile>
                ${project.build.directory}/jaxws/stale/HelloService.wsdl.stale
        </staleFile>
        </configuration>
        </execution>
        <execution>
        <id>Id2</id>
        <goals>
               <goal>wsimport</goal>
        </goals>
        <configuration>
            <wsdlLocation>wsdl/GoodByeService.wsdl</wsdlLocation>
         <wsdlFiles>
                <wsdlFile>GoodByeService.wsdl</wsdlFile>
        </wsdlFiles>
        <staleFile>
                ${project.build.directory}/jaxws/stale/GoodByeService.wsdl.stale
        </staleFile>
        </configuration>
        </execution>
    </executions>
    <configuration>
       <target>2.1</target>
       <xjcArgs>
        <xjcArg>-XautoNameResolution</xjcArg>
       </xjcArgs>
       <bindingDirectory>src/jaxws</bindingDirectory>
       <keep>true</keep>
       <wsdlDirectory>src/jaxws/wsdl</wsdlDirectory>
       <packageName>com.test.hello.soap</packageName>
    </configuration>

这工作得非常好。并且两个wsdl文件都是在packageName(com.test.hello.soap)中生成的,但我希望在单独的packageName或位置生成带有Id2的wsdl文件。

有人可以告诉我该怎么做吗?

2 个答案:

答案 0 :(得分:1)

示例底部的<configuration>标记定义了两个执行之间通用的配置值。

如果您希望<packageName>的值为Id1具有一个值而Id2具有另一个值,则只需将<packageName>配置值移动到<configuration>块中以执行每次执行

所以看起来像:

<executions>
    <execution>
        <id>Id1</id>
        <goals>
            <goal>wsimport</goal>
        </goals>
        <configuration>
            <wsdlLocation>wsdl/HelloService.wsdl</wsdlLocation>
            <wsdlFiles>
                <wsdlFile>HelloService.wsdl</wsdlFile>
            </wsdlFiles>
            <staleFile>
                ${project.build.directory}/jaxws/stale/HelloService.wsdl.stale
            </staleFile>
            <!-- packageName value for Id1 -->
            <packageName>com.test.hello.soap</packageName>
        </configuration>
    </execution>
    <execution>
        <id>Id2</id>
        <goals>
           <goal>wsimport</goal>
        </goals>
        <configuration>
            <wsdlLocation>wsdl/GoodByeService.wsdl</wsdlLocation>
            <wsdlFiles>
                <wsdlFile>GoodByeService.wsdl</wsdlFile>
            </wsdlFiles>
            <staleFile>
                ${project.build.directory}/jaxws/stale/GoodByeService.wsdl.stale
            </staleFile>
            <!-- packageName value for Id2 -->
            <packageName>com.test.goodbye.soap</packageName>
        </configuration>
    </execution>
</executions>
<configuration>
    <target>2.1</target>
    <xjcArgs>
    <xjcArg>-XautoNameResolution</xjcArg>
    </xjcArgs>
    <bindingDirectory>src/jaxws</bindingDirectory>
    <keep>true</keep>
    <wsdlDirectory>src/jaxws/wsdl</wsdlDirectory>
    <!-- packageName has been removed from here -->
</configuration>

答案 1 :(得分:0)

我不知道要在pom.xml中进行配置,但是wsdl2java工具有一个-p选项,允许您分别为每个命名空间指定包。语法为here