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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5140240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:39:37  来源:igfitidea点击:

How to generate Java source from WSDL in Pom.xml?

javawsdlpom.xml

提问by jimmy

I have a pom file which is generating source from WSDL files which is designed something like this.

我有一个 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>

This is working really fine. And both the wsdl files are generated in the packageName (com.test.hello.soap) but I want the wsdl file with Id2 to be generated in a separate packageName or location.

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

Can someone tell me how to do that please?

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

采纳答案by joelittlejohn

The <configuration>tag at the bottom of your example defines config values that are common between the two executions.

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

If you want the value of <packageName>to have one value for Id1 and another value for Id2, you simply need to move the <packageName>config value into the <configuration>block for each execution.

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

So, it looks like :

所以,它看起来像:

<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>

回答by asgs

I don't know the configuration to be made in pom.xml but the wsdl2java tool has a -p option that will allow you to specify the package for each namespace separately. The syntax is here

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