users@jaxb.java.net

Resolve error with JAXB XJC

From: Young Matthew (4004) <"Young>
Date: Mon, 27 Dec 2010 14:54:50 +0000

hej,

If I run the XFCFacade with the following arguments:
@Test
public void execute() throws Throwable {
String[] args = {
"-extension",
"-d",
"C:/temp",
"-b",
"C:/workshop/klistret/CMDB CI/configuration/build/jaxb.binding.xml",
"C:/workshop/klistret/CMDB CI/src/xsd",
"-Xcollection-setter-injector",
"-Xinject-code",
"-Xci"};

XJCFacade.main(args);
XJC generates this type of errors:
parsing a schema...
[ERROR] src-resolve: Cannot resolve the name 'element:Component' to a(n) 'type definition' component.
line 30 of file:/C:/workshop/klistret/CMDB%20CI/src/xsd/element/component/hardware.cmdb.xsd
But if I specify a chain of files rather than giving a directory the XJC parser works fine even if the xsd files are in a jumbled order:
String[] args = {
"-extension",
"-d",
"C:/temp",
"-b",
"C:/workshop/klistret/CMDB CI/configuration/build/jaxb.binding.xml",
"C:/workshop/klistret/CMDB CI/src/xsd/element/component.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/element/component/hardware.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/pojo.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/commons.cmdb.xsd",
"C:/workshop/klistret/CMDB CI/src/xsd/xmlschemaNamespace.xsd",
"-Xcollection-setter-injector",
"-Xinject-code",
"-Xci"};

XJCFacade.main(args);
Using JAXB 2.2 but have tried 2.2.2 and 2.2.3 releases without any luck. Compiling with Java 1.6. The hardware.cmdb.xsd file imports the component.cmdb.xsd to extend a complex type which subsequently extends a base complex type. So there is an import dependency between the xsd files. Debugging I see the the opt.grammars picks up all the xsd files when using just the directory there after I get lost in the XMLSchemaLoader class.

Example of the xsd files:
[hardware.cmdb.xsd]
<xs:schema xmlns="http://www.klistret.com/cmdb/ci/element/component"
targetNamespace="http://www.klistret.com/cmdb/ci/element/component"
xmlns:element="http://www.klistret.com/cmdb/ci/element"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" jaxb:version="2.0">

<xs:import namespace="http://www.klistret.com/cmdb/ci/element"
schemaLocation="../component.cmdb.xsd" />

<xs:complexType name="Hardware" abstract="true">
<xs:annotation>
<xs:documentation></xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="element:Component"></xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="Hardware" type="Hardware"></xs:element>
</xs:schema>


[component.cmdb.xsd]

<xs:schema xmlns="http://www.klistret.com/cmdb/ci/element"
targetNamespace="http://www.klistret.com/cmdb/ci/element"
xmlns:commons="http://www.klistret.com/cmdb/ci/commons"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" jaxb:version="2.0">

<xs:import namespace="http://www.klistret.com/cmdb/ci/commons"
schemaLocation="../commons.cmdb.xsd" />

<xs:complexType name="Component" abstract="true">
<xs:complexContent>
<xs:extension base="commons:Element" />
</xs:complexContent>
</xs:complexType>

<xs:element name="Component" type="Component"></xs:element>
</xs:schema>