使用 jaxws-maven-plugin 控制 JAX-WS wsdlLocation 属性值(绝对路径)

2022-09-01 19:15:16

我有一个 JAX-WS 驱动的 Web 服务,我们从另一个 Maven 模块(我将调用该模块)中生成一个 Web 服务客户端的 WSDL。ws-consumer

无论好坏,我们将“已发布的 WSDL”(服务在发布时持有/生成的 WSDL 和 XSD 版本)复制到我们的文件夹中,然后从 org.jvnet 使用以下命令(截断)配置生成客户端:src/wsdlws-consumerjaxws-maven-pluginjaxws:wsimport

    <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.1</version>
        <executions>
            <execution>
                <!--phase>generate-sources</phase -->
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <wsdlDirectory>src/main/resources/META-INF/wsdl/</wsdlDirectory>
                    <wsdlFiles>
                        <wsdlFile>MyWS/MyWS.wsdl</wsdlFile>
                    </wsdlFiles>
                </configuration>
            </execution>
        </executions>
    </plugin>

现在,生成的客户端代码在类级别应用了以下批注:

@WebServiceClient(name = "MyWS", targetNamespace = "http://myws/blah", wsdlLocation = "**file:/C:/some/absolute/path/src/main/resources/META-INF/wsdl/MyWS/MyWS.wsdl"**)

强调我的

正如您所希望的,属性值具有硬编码的绝对路径,在部署服务时将不正确。wsdlLocation

有没有办法通过将其设置为仅或其他值来“控制”它?META-INF/wsdl/MyWS/MyWS.wsdl


答案 1

使用Codehaus插件可以:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxws-maven-plugin</artifactId>
   <version>1.9</version>
   <executions>
     <execution>
       <goals>
         <goal>wsimport</goal>
       </goals>
     </execution>
   </executions>
   <configuration>
     <keep>true</keep>
     <verbose>true</verbose>
     <wsdlDirectory>../wscontract/src/main/resources/wsdl</wsdlDirectory>
     <wsdlLocation>wsdl/MaintainAddress.wsdl</wsdlLocation>
     <sourceDestDir>src/main/java</sourceDestDir>
     <bindingDirectory>.</bindingDirectory>
     <bindingFiles>
       <bindingFile>jaxb/xsdbindings.xml</bindingFile>
       <bindingFile>jaxb/wsdlbindings.xml</bindingFile>
     </bindingFiles>
   </configuration>
</plugin>

也许您正在使用的插件具有类似的选项,或者您可以考虑切换。

您还可以显式设置 WSDL,在这种情况下,将忽略此属性,尽管这可能不适用于容器管理的应用程序。

此处的示例代码。


答案 2

使用 wsdlLocation 与 org.jvnet.jax-ws-commons 中的 jaxws-maven-plugin:

<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
    <execution>
        <goals>
            <goal>wsimport</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
    <wsdlFiles>
        <wsdlFile>arsdev.wsdl</wsdlFile>
    </wsdlFiles>
    <wsdlLocation>wsdl/*</wsdlLocation>
    <!-- Keep generated files -->
    <keep>true</keep>
    <packageName>jaxws.remedy.client.generated</packageName>
    <!-- generated source files destination -->
    <sourceDestDir>target/generated-code/src</sourceDestDir>
</configuration>
</plugin>

推荐