简体   繁体   中英

Generating Java classes from XSD schema

I am trying to generate java classes from XSD schema http://docs.oasis-open.org/ws-sx/ws-trust/200512/ws-trust-1.3.xsd .

For this I am using jaxb2-maven-plugin with xjc to generate those glasses. But run into following errors

http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd [87,40]
org.xml.sax.SAXParseException; systemId: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd; lineNumber: 87; columnNumber: 40; A class/interface with the same name "com.abccompany.wstrust.ReferenceType" is already in use. Use a class customization to resolve this conflict.

[ERROR] http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd [97,35]
org.xml.sax.SAXParseException; systemId: http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd; lineNumber: 97; columnNumber: 35; (Relevant to above error) another "ReferenceType" is generated from here.

[ERROR] http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd [87,40]
com.sun.istack.SAXParseException2; systemId: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd; lineNumber: 87; columnNumber: 40; Two declarations cause a collision in the ObjectFactory class.

[ERROR] http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd [97,35]
com.sun.istack.SAXParseException2; systemId: http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd; lineNumber: 97; columnNumber: 35; (Related to above error) This is the other declaration.
[ERROR] http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd [152,58]
com.sun.istack.SAXParseException2; systemId: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd; lineNumber: 152; columnNumber: 58; Two declarations cause a collision in the ObjectFactory class
[ERROR] http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd [96,52]
com.sun.istack.SAXParseException2; systemId: http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd; lineNumber: 96; columnNumber: 52; (Related to above error) This is the other declaration.

So I tried to use bindings to resolve the conflict, this way

<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" schemaLocation="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" >
    <jxb:bindings node="//xsd:complexType[@name='ReferenceType']">
        <jxb:class name="AbstractReferenceType1" />
    </jxb:bindings>
</jxb:bindings>

But I still get following errors

[ERROR] http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd [152,58]
com.sun.istack.SAXParseException2; systemId: http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd; lineNumber: 152; columnNumber: 58; Two declarations cause a collision in the ObjectFactory class
[ERROR] http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd [96,52]
com.sun.istack.SAXParseException2; systemId: http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd; lineNumber: 96; columnNumber: 52; (Related to above error) This is the other declaration.

Tried to add bindings for xmldsig-core-schema.xsd schema, but it is not working. How do you accurately find out this line number and column number mentioned in the error? If I just copy the schema in notepad, that line number comes to non-relevant xml tag.

Have anyone tried to generate these classes?

As suggest by @KarlNicholas, I ran xjc without any other option and it generated the classes for me. Every time, I passed -p as an option, it would throw an error that i posted in question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM