JAXB / Maven JAX-WS:全局bindings.xml引用特定的WSDL

时间:2015-09-04 15:22:11

标签: java maven jaxb jaxws-maven-plugin

我正在使用Maven JAXWS插件和bindings.xml文件来覆盖从WSDL生成的JAXB类字段的Java类型,但是在使用JAX-WS Maven插件从多个WSDL生成Java类时会出现问题。 / p>

我的项目结构是:

- src
  - jaxws
    - bindings.xml
  - main
    - resources
      - wsdl
        - Wsdl1.wsdl
        - Wsdl1.xsd
        - Wsdl2.wsdl
        - Wsdl2.xsd

Wsdl1.wsdl引用Wsdl1.xsdWsdl2.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>

My 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,它在处理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>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

为除Wsdl2.wsdl之外的所有WSDL创建一次wsimport执行,为Wsdl2.wsdl创建另一次执行。这样,您可以为每个执行配置不同的配置,并为每个执行指定jaxb绑定。