从 XSD 模式生成 Java 类
Generating Java classes from XSD schema
我正在尝试从 XSD 架构 http://docs.oasis-open.org/ws-sx/ws-trust/200512/ws-trust-1.3.xsd 生成 java 类。
为此,我使用 jaxb2-maven-plugin
和 xjc
来生成这些眼镜。但是 运行 进入以下错误
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.
所以我尝试使用绑定来解决冲突,这样
<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>
但我仍然遇到以下错误
[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.
试图为 xmldsig-core-schema.xsd
架构添加绑定,但它不起作用。你如何准确地找出错误中提到的这个行号和列号?如果我只是在记事本中复制架构,则该行号会出现在不相关的 xml 标记中。
有没有人试过生成这些类?
正如@KarlNicholas 所建议的,我 运行 xjc
没有任何其他选项,它为我生成了 类。每次,我将 -p
作为选项传递,它都会抛出我发布的错误。
我正在尝试从 XSD 架构 http://docs.oasis-open.org/ws-sx/ws-trust/200512/ws-trust-1.3.xsd 生成 java 类。
为此,我使用 jaxb2-maven-plugin
和 xjc
来生成这些眼镜。但是 运行 进入以下错误
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.
所以我尝试使用绑定来解决冲突,这样
<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>
但我仍然遇到以下错误
[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.
试图为 xmldsig-core-schema.xsd
架构添加绑定,但它不起作用。你如何准确地找出错误中提到的这个行号和列号?如果我只是在记事本中复制架构,则该行号会出现在不相关的 xml 标记中。
有没有人试过生成这些类?
正如@KarlNicholas 所建议的,我 运行 xjc
没有任何其他选项,它为我生成了 类。每次,我将 -p
作为选项传递,它都会抛出我发布的错误。