使用JAXB外部配置文件绑定schema文件
Illegal class inheritance loop.
使用JAXB 2.0以上版本,使用schema文件绑定Java对象,并配置了外部配置文件binding.xjb后,出现这个错误。
现已解决,如下:
1、schema文件po.xsd:
1
<?
xml version="1.0" encoding="utf-8"
?>
2 < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" elementFormDefault ="qualified" attributeFormDefault ="unqualified" >
3 < xs:element name ="AAAA" >
4 < xs:annotation >
5 < xs:documentation > Root </ xs:documentation >
6 </ xs:annotation >
7 < xs:complexType >
8 < xs:sequence >
9 < xs:element name ="DDDD" type ="xs:string" default ="Hello!" />
10 < xs:element name ="VVVV" type ="xs:integer" default ="2008" />
11 < xs:element name ="SA" minOccurs ="0" >
12 < xs:complexType >
13 < xs:sequence >
14 < xs:element name ="BBBB" type ="xs:string" />
15 < xs:element name ="CCCC" type ="xs:string" />
16 < xs:element name ="TTTT" type ="xs:dateTime" minOccurs ="0" />
17 < xs:element name ="PPPP" type ="xs:string" minOccurs ="0" />
18 < xs:element name ="RRRR" type ="xs:base64Binary" />
19 < xs:element name ="CACA" maxOccurs ="unbounded" >
20 < xs:complexType >
21 < xs:sequence >
22 < xs:element name ="CA" type ="xs:base64Binary" maxOccurs ="unbounded" />
23 < xs:element name ="CRCR" minOccurs ="0" />
24 </ xs:sequence >
25 </ xs:complexType >
26 </ xs:element >
27 </ xs:sequence >
28 </ xs:complexType >
29 </ xs:element >
30 </ xs:sequence >
31 </ xs:complexType >
32 </ xs:element >
33 </ xs:schema >
2 < xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" elementFormDefault ="qualified" attributeFormDefault ="unqualified" >
3 < xs:element name ="AAAA" >
4 < xs:annotation >
5 < xs:documentation > Root </ xs:documentation >
6 </ xs:annotation >
7 < xs:complexType >
8 < xs:sequence >
9 < xs:element name ="DDDD" type ="xs:string" default ="Hello!" />
10 < xs:element name ="VVVV" type ="xs:integer" default ="2008" />
11 < xs:element name ="SA" minOccurs ="0" >
12 < xs:complexType >
13 < xs:sequence >
14 < xs:element name ="BBBB" type ="xs:string" />
15 < xs:element name ="CCCC" type ="xs:string" />
16 < xs:element name ="TTTT" type ="xs:dateTime" minOccurs ="0" />
17 < xs:element name ="PPPP" type ="xs:string" minOccurs ="0" />
18 < xs:element name ="RRRR" type ="xs:base64Binary" />
19 < xs:element name ="CACA" maxOccurs ="unbounded" >
20 < xs:complexType >
21 < xs:sequence >
22 < xs:element name ="CA" type ="xs:base64Binary" maxOccurs ="unbounded" />
23 < xs:element name ="CRCR" minOccurs ="0" />
24 </ xs:sequence >
25 </ xs:complexType >
26 </ xs:element >
27 </ xs:sequence >
28 </ xs:complexType >
29 </ xs:element >
30 </ xs:sequence >
31 </ xs:complexType >
32 </ xs:element >
33 </ xs:schema >
2、外部配置文件binding.xjb:
1
<
jxb:bindings
version
="1.0"
2 xmlns:jxb ="http://java.sun.com/xml/ns/jaxb"
3 xmlns:xs ="http://www.w3.org/2001/XMLSchema" >
4 < jxb:bindings schemaLocation ="po.xsd" node ="/xs:schema" >
5 < jxb:globalBindings
6 fixedAttributeAsConstantProperty ="false"
7 collectionType ="java.util.Vector"
8 typesafeEnumBase ="xs:NCName"
9 choiceContentProperty ="false"
10 typesafeEnumMemberName ="generateError"
11 enableFailFastCheck ="false"
12 generateIsSetMethod ="false"
13 underscoreBinding ="asCharInWord" />
14 < jxb:schemaBindings >
15 < jxb:package name ="test.po" >
16 < jxb:javadoc > <![CDATA[ <body>Package level documentation for generated package primer.myPo.</body> ]]> </ jxb:javadoc >
17 </ jxb:package >
18 < jxb:nameXmlTransform >
19 < jxb:elementName suffix ="Element" />
20 </ jxb:nameXmlTransform >
21 </ jxb:schemaBindings >
22
23 < jxb:bindings node ="//xs:element[@name='AAAA']" >
24
25 < jxb:class name ="Article" >
26 < jxb:javadoc > A < b>Purchase Order < /b> Article. </ jxb:javadoc >
27 </ jxb:class >
28
29 < jxb:bindings node =".//xs:element[@name='DDDD']" >
30 < jxb:property name ="hi" />
31 </ jxb:bindings >
32
33 < jxb:bindings node =".//xs:element[@name='VVVV']" >
34 < jxb:property name ="year" />
35 </ jxb:bindings >
36
37
38 < jxb:bindings node =".//xs:element[@name='SA']" >
39 < jxb:property name ="content" >
40 < jxb:baseType name ="Content" />
41 </ jxb:property >
42
43 < jxb:bindings node ="./xs:complexType" >
44 < jxb:class name ="Content" />
45
46 < jxb:bindings node =".//xs:element[@name='BBBB']" >
47 < jxb:property name ="title" />
48 </ jxb:bindings >
49
50 < jxb:bindings node =".//xs:element[@name='CCCC']" >
51 < jxb:property name ="subTitle" />
52 </ jxb:bindings >
53
54 < jxb:bindings node =".//xs:element[@name='TTTT']" >
55 < jxb:property name ="pubDate" />
56 </ jxb:bindings >
57
58 < jxb:bindings node =".//xs:element[@name='PPPP']" >
59 < jxb:property name ="organize" />
60 </ jxb:bindings >
61
62 < jxb:bindings node =".//xs:element[@name='RRRR']" >
63 < jxb:property name ="contentBinary" />
64 </ jxb:bindings >
65
66 < jxb:bindings node =".//xs:element[@name='CACA']" >
67 < jxb:property name ="licence" >
68 < jxb:baseType name ="Licence" />
69 </ jxb:property >
70
71 < jxb:bindings node ="./xs:complexType" >
72 < jxb:class name ="Licence" />
73 < jxb:bindings node =".//xs:element[@name='CA']" >
74 < jxb:property name ="licenceBinary" />
75 </ jxb:bindings >
76 < jxb:bindings node =".//xs:element[@name='CRCR']" >
77 < jxb:property name ="licenceNo" />
78 </ jxb:bindings >
79 </ jxb:bindings >
80 </ jxb:bindings >
81 </ jxb:bindings >
82
83 </ jxb:bindings >
84
85 </ jxb:bindings >
86
87
88 </ jxb:bindings >
89 </ jxb:bindings >
2 xmlns:jxb ="http://java.sun.com/xml/ns/jaxb"
3 xmlns:xs ="http://www.w3.org/2001/XMLSchema" >
4 < jxb:bindings schemaLocation ="po.xsd" node ="/xs:schema" >
5 < jxb:globalBindings
6 fixedAttributeAsConstantProperty ="false"
7 collectionType ="java.util.Vector"
8 typesafeEnumBase ="xs:NCName"
9 choiceContentProperty ="false"
10 typesafeEnumMemberName ="generateError"
11 enableFailFastCheck ="false"
12 generateIsSetMethod ="false"
13 underscoreBinding ="asCharInWord" />
14 < jxb:schemaBindings >
15 < jxb:package name ="test.po" >
16 < jxb:javadoc > <![CDATA[ <body>Package level documentation for generated package primer.myPo.</body> ]]> </ jxb:javadoc >
17 </ jxb:package >
18 < jxb:nameXmlTransform >
19 < jxb:elementName suffix ="Element" />
20 </ jxb:nameXmlTransform >
21 </ jxb:schemaBindings >
22
23 < jxb:bindings node ="//xs:element[@name='AAAA']" >
24
25 < jxb:class name ="Article" >
26 < jxb:javadoc > A < b>Purchase Order < /b> Article. </ jxb:javadoc >
27 </ jxb:class >
28
29 < jxb:bindings node =".//xs:element[@name='DDDD']" >
30 < jxb:property name ="hi" />
31 </ jxb:bindings >
32
33 < jxb:bindings node =".//xs:element[@name='VVVV']" >
34 < jxb:property name ="year" />
35 </ jxb:bindings >
36
37
38 < jxb:bindings node =".//xs:element[@name='SA']" >
39 < jxb:property name ="content" >
40 < jxb:baseType name ="Content" />
41 </ jxb:property >
42
43 < jxb:bindings node ="./xs:complexType" >
44 < jxb:class name ="Content" />
45
46 < jxb:bindings node =".//xs:element[@name='BBBB']" >
47 < jxb:property name ="title" />
48 </ jxb:bindings >
49
50 < jxb:bindings node =".//xs:element[@name='CCCC']" >
51 < jxb:property name ="subTitle" />
52 </ jxb:bindings >
53
54 < jxb:bindings node =".//xs:element[@name='TTTT']" >
55 < jxb:property name ="pubDate" />
56 </ jxb:bindings >
57
58 < jxb:bindings node =".//xs:element[@name='PPPP']" >
59 < jxb:property name ="organize" />
60 </ jxb:bindings >
61
62 < jxb:bindings node =".//xs:element[@name='RRRR']" >
63 < jxb:property name ="contentBinary" />
64 </ jxb:bindings >
65
66 < jxb:bindings node =".//xs:element[@name='CACA']" >
67 < jxb:property name ="licence" >
68 < jxb:baseType name ="Licence" />
69 </ jxb:property >
70
71 < jxb:bindings node ="./xs:complexType" >
72 < jxb:class name ="Licence" />
73 < jxb:bindings node =".//xs:element[@name='CA']" >
74 < jxb:property name ="licenceBinary" />
75 </ jxb:bindings >
76 < jxb:bindings node =".//xs:element[@name='CRCR']" >
77 < jxb:property name ="licenceNo" />
78 </ jxb:bindings >
79 </ jxb:bindings >
80 </ jxb:bindings >
81 </ jxb:bindings >
82
83 </ jxb:bindings >
84
85 </ jxb:bindings >
86
87
88 </ jxb:bindings >
89 </ jxb:bindings >
3、运行:
1
xjc -b binding.xjb -d gen po.xsd
完毕!