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 package path -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ファイルにメッセージフィールドがあるため、メッセージはすでに定義されています。エラーが報告されないように、ファイルを1つずつ転送することをお勧めします。

 

おすすめ

転載: blog.csdn.net/langeldep/article/details/100175352