質問

I use maven-jaxb2-plugin to generate jaxb annotated classes from xsd. I have many xsd files like those:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="A3">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="loginPartner">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="login"/>
              <xs:element type="xs:string" name="password"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="A3">
    <xs:complexType>
      <xs:sequence>
        <xs:element type="xs:string" name="errorCode"/>
        <xs:element type="xs:string" name="errorDescription"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

When I run maven plugin it gives me an error:

[ERROR] Error while parsing schema(s).Location [ file:schema1.xsd{10,16}]. org.xml.sax.SAXParseException: 'A3' is already defined

Is there any way to fix this? Actually I have many XSDs representing request/response messages to/from server. I want to simplify creating, validating, parsing messages. Maybe is there another solution for this?

役に立ちましたか?

解決

I had a similar problem; I had two separate and independent WSDL (each with several schema definitions in each) that I was running through JAXB (via the maven-jaxb2-plugin) to generate mapping classes.

My WSDL's shared a duplicate schema definition that was causing XJC to choke.

Because they were both independent, I was able to generate JAXB mappings by running two separate executions of the maven-jaxb2-plugin - one for each WSDL (covered here - How can I tell jaxb / Maven to generate multiple schema packages?).

他のヒント

You cannot have conflicting element definitions within the same namespace. This is same as not allowing multiple classes with the same name in a given package in Java. Your best bet is to define them with different names or in different namespaces.

you can rename the second or the first A3 of your xsd in your jaxb binding file

<jaxb:bindings schemaLocation="filePath.xsd" node="/xs:schema">
        <jaxb:bindings node="//xs:element[@name='A3']">
            <jaxb:property name="SecondA3"/>
        </jaxb:bindings>
</jaxb:bindings>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top