How to share/reuse classes between modularized JAXB/JAX-WS maven modules?

20 Views Asked by At

I have the following maven project where I generate java classes from XML schemas in a first module then try to use those classes in a second module. The second module defines a WSDL which uses the schemas defined in the first module.

my-project
+- xsd
   +- src
      +- main
         +- resources
            +- xsd
               +- foo.xsd    [defines some base types like foo:UUIDType]
               +- bar.xsd    [imports foo.xsd]
               +- baz.xsd    [imports foo.xsd + bar.xsd]
         +- jaxb
            +- bindings.xml  [defines <jaxb:globalBindings> with <xjc:javaType name="java.util.UUID" xmlType="foo:UUIDType" adapter="...UuidXmlAdapter"/>]
+- wsdl
   +- src
      +- main
         +- resources
            +- wsdl
               +- qux.wsdl    [imports qux.xsd]
               +- qux.xsd     [imports foo.xsd + bar.xsd, defines requests and responses types for the various operations in qux.wsdl]
         +- jaxws
            +- catalog.cat    [defines how foo.xsd and bar.xsd should be resolved]
            +- bindings.xml   [defines <jaxb:globalBindings> with <xjc:javaType name="java.util.UUID" xmlType="foo:UUIDType" adapter="...UuidXmlAdapter"/>]

The xsd module uses the org.jvnet.jaxb:jaxb-maven-plugin to generate java classes from the schemas.

The wsdl module depends on the xsd project and uses the org.apache.cxf:cxf-codegen-plugin to generate the various JAX-WS classes. The wsdl module uses the sun-jaxb.episode created by the xsd module.

If I don't include the bindings.xml in the WSDL module, all elements of type foo:UUIDType declared in qux.xsd will not be of the good type (and won't useUuidXmlAdapter).

If I do include it, I got the following error which seems to indicate that the <globalBindings/> is re-applied to the schemas from the first module.

Exception in thread "main" org.apache.cxf.tools.common.ToolException: file:/.../myproject/wsdl/src/main/jaxws/bindings.xml [line,col]: compiler was unable to honor this conversion customization. It is attached to a wrong place, or its inconsistent with other bindings.
[WARNING] file:/.../myproject/xsd/src/main/resources/xsd/foo.xsd [line,col]: (the above customization is attached to the following location in the schema)

What can I do? Do I have to create specific schema bindings for each XSD files (and repeat the <globalBindings/> under each <jaxb:bindings schemaLocation="..."/>) or is there a better solution?

0

There are 0 best solutions below