【发布时间】:2012-01-27 21:34:53
【问题描述】:
我使用 maven-jaxb2-plugin 从 xsd 生成带有 jaxb 注释的类。我有很多这样的 xsd 文件:
<?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>
当我运行 maven 插件时,它给了我一个错误:
[错误] 解析架构时出错。位置 [ 文件:schema1.xsd{10,16}]。 org.xml.sax.SAXParseException: 'A3' 已经存在 定义
有没有办法解决这个问题? 实际上,我有许多 XSD 代表发往/来自服务器的请求/响应消息。我想简化创建、验证、解析消息。也许还有其他解决方案?
【问题讨论】:
-
你能从你的
pom.xml发布你的插件配置吗?我现在找不到(到达)maven-jaxb2-plugin的文档,而且我不知道所有选项。如果可行,请尝试将targetNamespace="http://whatever"属性添加到您的架构中以区分具有相同名称的类型。可以将每个模式文件编译到不同的 Java 包中。那也可以。为此,您可能必须为插件指定 multipe executions。
标签: java xml xsd jaxb2 maven-jaxb2-plugin