问题
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