通过XSD文件生成JAVA对象

c:\Program Files\Java\jdk1.8.0_101\bin>xjc.exe  -p  "io.xsd.xml"  -encoding "UTF-8"  ".\xsdTOxml\MyField.xsd"  -d  ".\xsdTOxml"
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Duser.language=en -Duser.country=US
parsing a schema...
compiling a schema...
io\xsd\xml\Message.java
io\xsd\xml\ObjectFactory.java

命令格式:   xjc.exe  -p  包的路径   -encoding "UTF-8"   文件名.xsd  -d  目标存放文件夹

[ERROR] schema_reference.4: Failed to read schema document 'file:/E:/KGCCDEV/xsdTOxml/io.xsd.xml', because 
1) could not find the document; 
2) the document could not be read; 
3) the root element of the document is not <xsd:schema>.unknown location

Failed to parse a schema.

踩坑点1: 不能用绝对路径, 不然就会报上面的错误。要用和xjc.exe 同级目录的相对路径

[ERROR] 'Message' is already defined
  line 1697 of file:/C:/Program%20Files/Java/jdk1.8.0_101/bin/xsdTOxml/Field.xsd

[ERROR] (related to above error) the first definition appears here
  line 4 of file:/C:/Program%20Files/Java/jdk1.8.0_101/bin/xsdTOxml/Field.xsd

Failed to parse a schema.

踩坑点2: 目录下面的XSD文件如果有多个, 并且不同的文件里有相同的字段名,就会报错,我的是两个XSD文件里都有Message这个字段, 所以报 Message is already  defined。 最好是一个文件一个文件的转,这样肯定不会报错。

猜你喜欢

转载自blog.csdn.net/langeldep/article/details/100175352