下面是演示该问题的最小示例。三个模式文件:A。xsd 、 B。xsd 、 C。Xsd 在以下导入配置中:
C.xsd ---------------- imports ----------------> A.xsd
/
---- imports ---> B.xsd --- imports ----/
。xsd由C直接导入。xsd,再间接地通过B.xsd。当尝试运行xjc(版本。2.2.4) on 当同时使用目录和绑定文件(即使是空文件)时,xsd
A.xsd
<schema targetNamespace="foo://a"
xmlns="http://www.w3.org/2001/XMLSchema">
<simpleType name="year">
<restriction base="dateTime">
<pattern value="d{4}"/>
</restriction>
</simpleType>
</schema>
B.xsd
<schema targetNamespace="foo://b"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="foo://a" schemaLocation="boo://a.xsd"/>
</schema>
C.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="foo://c">
<import namespace="foo://a" schemaLocation="A.xsd"/>
<import namespace="foo://b" schemaLocation="B.xsd"/>
</schema>
catalog.xml
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="boo://a.xsd" uri="A.xsd"/>
</catalog>
binding.xjb
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1"/>
给定上述文件,所有文件都放在同一目录中,下面的调用成功:
xjc -d src -extension -catalog catalog.xml C.xsd
而下面的调用:
xjc -d src -extension -catalog catalog.xml C.xsd -b bindings.xjb
…在失败时显示类似bug的消息(指向某些内部混乱?):
parsing a schema...
[ERROR] 'year' is already defined
line 8 of file:/home/brutus/A.xsd
[ERROR] (related to above error) the first definition appears here
line 3 of file:/home/brutus/A.xsd
Failed to parse a schema.
更新发布了一个bug报告
我使用Mac上的JDK 1.7.0_21-b12附带的XJC运行了您的示例,它工作得很好。您只需要从JAXB参考实现(参见:https://jaxb.java.net/)切换到不更新的XJC版本,就可以使您的用例正常工作。
查看更多信息
- http://blog.bdoughan.com/2011/10/jaxb-xjc-imported-schemas-and-xml.html
我有一个非常相似的问题,如果不是相同的。你能找到解决办法吗?jaxb-ri-2.2.7
、xjc 2.2.4-2 (OpenJDK 7u25)
、jaxb-ri-2.2.1.1-4 of GlassFish
试验
public
目录项结合使用时,一切都可以正常工作。不幸的是,我不能调整模式。
这里有一个小例子。
失败:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:test="http://www.test.com/1.0" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" targetNamespace="http://www.test.com/1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
<import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd"/>
<element name="TestElement" type="test:TestType"/>
<complexType name="TestType">
<sequence>
<element name="name" type="string"/>
</sequence>
<attribute ref="xlink:title" use="required"/>
</complexType>
</schema>
工作:<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:test="http://www.test.com/1.0" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" targetNamespace="http://www.test.com/1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
<import namespace="http://www.w3.org/1999/xlink"/>
<element name="TestElement" type="test:TestType"/>
<complexType name="TestType">
<sequence>
<element name="name" type="string"/>
</sequence>
<attribute ref="xlink:title" use="required"/>
</complexType>
</schema>
目录文件(两个):
<!DOCTYPE catalog
PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system
systemId="http://www.w3.org/1999/xlink.xsd"
uri="../schemas/xlink/1.0.0/xlinks.xsd"/>
<public
publicId="http://www.w3.org/1999/xlink"
uri="../schemas/xlink/1.0.0/xlinks.xsd"/>
</catalog>
执行(同时):
xjc schemas/xlink/1.0.0/xlinks.xsd schemas/test.xsd -b xjb/xlink.xjb -extension -d .build -catalog catalog/catalog.xml