我正在使用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
引用Wsdl1.xsd
,Wsdl2.wsdl
引用Wsdl2.xsd
,这两个WSDL和XSD没有共同之处。我无法修改WSDL和XSD。我想以
departureDate
中的特定类型(Flight
)覆盖特定字段(Wsdl2.xsd
)的Java类型。我的
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,但是对每个WSDL使用相同的
bindings.xml
。这样,由于在Wsdl1
中对Wsdl2.xsd
的引用,因此在处理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>
我该如何解决这个问题?
最佳答案
为除Wsdl2.wsdl之外的所有WSDL创建一个wsimport执行,为Wsdl2.wsdl创建另一个执行。这样,您可以为每个执行使用不同的配置,并为每个执行指定不同的jaxb绑定。