Generate Java class based on XSD without block substitution?

社会主义新天地 提交于 2019-12-10 18:14:06

问题


I am getting below error while maven build using jaxb(maven-jaxb2-plugin) compiler

A class/interface with the same name "org.somePackage.customer" is already in use.
    Use a class customization to resolve this conflict.
        at com.sun.tools.xjc.util.CodeModelClassFactory.createClass(CodeModelClassFactory.java:121)
        at com.sun.tools.xjc.util.CodeModelClassFactory.createClass(CodeModelClassFactory.java:82)
        at com.sun.tools.xjc.generator.bean.ImplStructureStrategy$1.createClasses(ImplStructureStrategy.java:82)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassDef(BeanGenerator.java:437)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.getClazz(BeanGenerator.java:469)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:194)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:166)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:290)
        at org.jvnet.mjiip.v_2_2.XJC22Mojo.generateCode(XJC22Mojo.java:70)

What does not work

 <xsd:element name="customer" >
         ........
 </xsd:element>
 <xsd:element name="permanentCustomer" type="customer"/>

What works

<xsd:element name="customer" block="substitution">
 ........
</xsd:element>
<xsd:element name="permanentCustomer" type="customer"/>

I am not sure why removing block attribute creating issue here ?

My guess is jaxb compiler again trying to create the customer class based on element name="permanentCustomer" which it has already created based on element name ="customer". So I don't want to create java object for permanentCustomer while unmarshalling as it has been already created while customer creation. Is there a way to do that ?

来源:https://stackoverflow.com/questions/31293874/generate-java-class-based-on-xsd-without-block-substitution

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