首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用XJC将XML模式转换为java类

使用XJC将XML模式转换为java类
EN

Stack Overflow用户
提问于 2012-06-10 20:34:39
回答 2查看 4.4K关注 0票数 1

我使用的是从这里下载的官方XSD模式:

http://docs.oasis-open.org/ubl/os-UBL-2.0.zip

(路径:xsd/maindoc/UBL Order-2.0.xsd)

当我使用下面的命令用XJC生成java类时,我总是在控制台中得到一个错误,我不知道如何处理这个错误。

命令:

代码语言:javascript
复制
xjc -d C:\Users\Oscar\Desktop\results -p com.ubl.order C:\Users\Oscar\Desktop\os-UBL-2.0\xsd\maindoc\UBL-Order-2.0.xsd

错误:

代码语言:javascript
复制
parsing a schema...
[WARNING] Simple type "UnitCodeContentType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 1.093, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
  line 38 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/CodeList_UnitCode_UNECE_7_04.xsd

[WARNING] Simple type "BinaryObjectMimeCodeContentType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 616, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
  line 38 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/CodeList_MIMEMediaTypeCode_IANA_7_04.xsd

[WARNING] Simple type "LanguageCodeContentType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 276, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
  line 38 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/CodeList_LanguageCode_ISO_7_04.xsd

compiling a schema...
[ERROR] A class/interface with the same name "com.ubl.order.LocationType" is already in use. Use a class customization to resolve this conflict.
  line 9890 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonAggregateComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LocationType" is generated from here.
  line 1543 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.TextType" is already in use. Use a class customization to resolve this conflict.
  line 2598 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "TextType" is generated from here.
  line 1070 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.NameType" is already in use. Use a class customization to resolve this conflict.
  line 1718 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "NameType" is generated from here.
  line 1105 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.AmountType" is already in use. Use a class customization to resolve this conflict.
  line 613 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "AmountType" is generated from here.
  line 57 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.MeasureType" is already in use. Use a class customization to resolve this conflict.
  line 1668 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "MeasureType" is generated from here.
  line 930 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.QuantityType" is already in use. Use a class customization to resolve this conflict.
  line 2143 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "QuantityType" is generated from here.
  line 1035 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.ChannelCodeType" is already in use. Use a class customization to resolve this conflict.
  line 763 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "ChannelCodeType" is generated from here.
  line 119 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.DocumentStatusCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1103 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "DocumentStatusCodeType" is generated from here.
  line 618 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.PackagingTypeCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1873 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "PackagingTypeCodeType" is generated from here.
  line 1113 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.TransportModeCodeType" is already in use. Use a class customization to resolve this conflict.
  line 2753 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "TransportModeCodeType" is generated from here.
  line 1708 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.AllowanceChargeReasonCodeType" is already in use. Use a class customization to resolve this conflict.
  line 603 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "AllowanceChargeReasonCodeType" is generated from here.
  line 19 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.TransportEquipmentTypeCodeType" is already in use. Use a class customization to resolve this conflict.
  line 2728 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "TransportEquipmentTypeCodeType" is generated from here.
  line 1609 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.PaymentMeansCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1978 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "PaymentMeansCodeType" is generated from here.
  line 1212 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.CurrencyCodeType" is already in use. Use a class customization to resolve this conflict.
  line 913 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "CurrencyCodeType" is generated from here.
  line 517 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.LongitudeDirectionCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1563 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LongitudeDirectionCodeType" is generated from here.
  line 915 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.SubstitutionStatusCodeType" is already in use. Use a class customization to resolve this conflict.
  line 2478 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "SubstitutionStatusCodeType" is generated from here.
  line 1411 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.LineStatusCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1528 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LineStatusCodeType" is generated from here.
  line 816 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.LatitudeDirectionCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1468 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LatitudeDirectionCodeType" is generated from here.
  line 717 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 9890 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonAggregateComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1543 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2598 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1070 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1718 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1105 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 613 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 57 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1668 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 930 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2143 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1035 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 763 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 119 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1103 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 618 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1873 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1113 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2753 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1708 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 603 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 19 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2728 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1609 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1978 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1212 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 913 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 517 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1563 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 915 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2478 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1411 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1528 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 816 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1468 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 717 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 166 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonAggregateComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 230 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

Failed to produce code.

我尝试的是不使用官方XSD,而是使用trang.jar生成自己的XSD。结果很好,我得到了生成的java类,但是当我使用JAXB (使用这些类)创建XML文档时,名称空间是不正常的。

所以,我想要的是使用非官方的XSD,但是修改(可能)才能使它工作。

如何解决这个问题以获得生成的类?

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-12 04:16:42

尝尝这个。

确保您的JDK版本是1.6或更高版本,在您的路径环境变量

  • $JAVA_HOME/bin环境变量

  • 中打开一个cmd并定位到/UBL-2.0/xsd/maindoc

  • run:xjc UBL-Order-2.0.xsd
票数 3
EN

Stack Overflow用户

发布于 2013-05-24 06:57:13

我创建了一个库,它封装了所有的UBL2.0和2.1耗能文件,以及一些与Java1.6和Maven一起使用的明智方法。有关详细信息,请查看https://github.com/phax/ph-ubl

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10972168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档