Maven Filtering of WSDL URL



我正在尝试使用资源过滤来生成WSDL的SOAP地址。但不知何故它不起作用。我将插件和资源元素编写为:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>process-urls</id>
<phase>clean</phase>
<goals>
<goal>resources</goal>
</goals>
<inherited>false</inherited>
<configuration>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
<filters>
<filter>src/main/resources/PO/WSDLFiles/ProcessOrder.wsdl</filter>
<filter>src/main/resources/DAC/WSDLFiles/InternalRequest.wsdl</filter>
</filters>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
<resources>
<resource>
<directory>src/main/resources/</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

我在、${protocol}${fullhostname}${port}下定义了一些配置文件值

我想修改的 WSDL 标签是这样的:

<service name="ProcessOrderService">
<port name="ProcessOrderSoapHttpPort" binding="tns:ProcessOrderSoapHttpBinding">
<soap:address location="${protocol}://${fullhostname}:${port}/PO/services/ProcessOrderSoapHttpPort"/>
</port>
</service>

当我运行我的pom文件时,该文件也有一个CXF插件来生成类,我看到JAVA对象中的URL是通过以下方式生成的:

${protocol}://${fullhostname}:${port}/PO/services/ProcessOrderSoapHttpPort

它只是按原样选取字符串,不应用任何值。你能告诉我我做错了什么吗?我猜测 WSDL 属性中的"导致了问题,但我可能是错的。

我假设Maven资源插件按预期工作。如果您使用调试模式mvn clean install -X您会发现一些其他信息,例如:

[DEBUG] file ProcessOrder.wsdl has a filtered file extension
[DEBUG] filtering /work/source/stackoverflow/wsdl-filtering/src/main/resources/PO/WSDLFiles/ProcessOrder.wsdl to /work/source/stackoverflow/wsdl-filtering/target/classes/PO/WSDLFiles/ProcessOrder.wsdl
[DEBUG] no use filter components

如果未指定<outputDirectory>,则默认输出文件夹将${project.build.outputDirectory}(目标/类(。

在这种情况下,只需在 CXF 插件中指定 wsdl 文件位置:

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.build.outputDirectory}/PO/WSDLFiles/ProcessOrder.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>

不要使用相同的目录,因为您将丢失原始文件的内容。结果将是一个空的 wsdl 文件。

此外,我建议修复资源插件配置。您可以使用<filters>来定义包含键值对的属性文件。请改用<resources><include>,就像在构建部分中所做的那样。

最新更新