Search code examples
jaxbjaxb2maven-jaxb2-plugin

JAXB maven plugin Two declarations cause a collision in the ObjectFactory class


I am using jaxb maven plugin to generate classes from schemas. I have 3 schemas which are separated in 3 maven modules.

Schema A in a.jar

Schema B in b.jar

Schema C in c.jar which imports a.jar and c.jar and use them.

A & B have some declarations with the same name and the same type.

<xs:element name="elementName" type="elementType" />

When generated C classes, I have an error

[ERROR] Error while generating code.Location [ file:/path/to/schema/A/a.xsd{7,58}].com.sun.istack.SAXParseException2: Two declarations cause a collision in the ObjectFactory class.

[ERROR] Error while generating code.Location [ file:/path/to/schema/B/b.xsd{7,58}].com.sun.istack.SAXParseException2: Two declarations cause a collision in the ObjectFactory class.

Does anyone have an idea to solve that?

Thanks in advance.


Solution

  • Using two imported elements with the same name will cause this error because JAXB will try to generate two attributes with the same name in a Java class, which isn't allowed.