Create a common xsd generated class to be used by other packages

冷暖自知 提交于 2019-11-27 21:21:11

There is a part in the maven-jaxb2-plugin documentation dedicated specifically to the separate schema compilation. But you can also achieve your goal with usual XJC bindings.

  • Do not use generatePackage in the plugin config, use jaxb:package in bindings, ex.:

    <jaxb:schemaBindings>
        <jaxb:package name="generatePackage"/>
    </jaxb:schemaBindings>
    
  • Use <jaxb:class ref="com.test.common.CommonType"/> on commonType in xjb/commons.xjb.

SO Disclaimer: I'm the author of the maven-jaxb2-plugin.

bdoughan

You can use the -episode extension in the JAXB XJC to handle this use case:

XJC call for common.xsd

xjc -d out -episode common.episode common.xsd

XJC call for objectA.xsd

The episode file produced from the first step is really a JAXB external bindings file that contains links between schema types and existing classes. This prevents XJC from regenerating these classes.

xjc -d out objectA.xsd -extension -b common.episode

For a Detailed Example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!