我正在使用 Maven JAXWS 插件和 bindings.xml 文件来覆盖从 WSDL 生成的 JAXB 类字段的 Java 类型,但是在使用 JAX-WS Maven 插件从多个 WSDL 生成 Java 类时遇到问题。
我的项目结构是:
- src
- jaxws
- bindings.xml
- main
- resources
- wsdl
- Wsdl1.wsdl
- Wsdl1.xsd
- Wsdl2.wsdl
- Wsdl2.xsd
Wsdl1.wsdl
references Wsdl1.xsd
,Wsdl2.wsdl
references Wsdl2.xsd
,这两个 WSDL 和 XSD 没有任何共同之处。我无法修改 WSDL 和 XSD。
departureDate
我想在特定类型 ( Flight
) 中覆盖特定字段 () 的 Java 类型Wsdl2.xsd
。
我bindings.xml
的是
<bindings version="2.0" extensionBindingPrefixes="xjc"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<xjc:javaType name="org.joda.time.LocalDate" xmlType="xs:date"
adapter="my.LocalDateAdapter"/>
<xjc:javaType name="org.joda.time.DateTime" xmlType="xs:dateTime"
adapter="my.DateTimeAdapter"/>
</globalBindings>
<bindings schemaLocation="../main/resources/wsdl/Wsdl2.xsd" node="/xs:schema">
<bindings node="//xs:complexType[@name='Flight']//xs:element[@name='departureDate']">
<xjc:javaType name="org.joda.time.LocalDateTime"
adapter="my.LocalDateTimeAdapter"/>
</bindings>
</bindings>
</bindings>
我的 Maven 配置是
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
</configuration>
</execution>
</executions>
</plugin>
当我使用该配置构建模块时,JAX-WS 会一一处理 WSDL,但bindings.xml
对它们中的每一个都使用相同的。这样,Wsdl1
由于对Wsdl2.xsd
in的引用,它在处理过程中失败bindings.xml
。
[INFO] --- jaxws-maven-plugin:2.2:wsimport (default) @ my-backend ---
[INFO] Processing: file:/D:/dev/Projects/my-api/my-backend/src/main/resources/wsdl/Wsdl1.wsdl
[INFO] jaxws:wsimport args: [-keep, -s, D:\dev\Projects\my-api\my-backend\target\generated-sources\wsimport, -encoding, UTF-8, -Xnocompile, -b, D:\dev\Projects\my-api\my-backend\src\jaxws\bindings.xml, file:/D:/dev/Projects/my-api/my-backend/src/main/resources/wsdl/Wsdl1.wsdl]
parsing WSDL...
[ERROR] "file:/D:/dev/Projects/my-api/my-backend/src/main/resources/wsdl/Wsdl2.xsd"
is not a part of this compilation. Is this a mistake for "file:/D:/dev/Projects/my-api/my-backend/src/main/resources/wsdl/Wsdl1.wsdl#types?schema1"?
line 11 of file:/D:/dev/Projects/my-api/my-backend/src/jaxws/bindings.xml
如果我选择仅Wsdl2.wsdl
由 JAX-WS 插件处理,那么一切正常。
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>Wsdl2.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
我该如何解决这个问题?