简体   繁体   English

JAXB XJC:如何生成Java类

[英]JAXB XJC: how to generate java classes

I'm trying to use xjc tool in order to generate java code according to some schemas. 我正在尝试使用xjc工具,以便根据某些模式生成Java代码。

I'm performing this command: 我正在执行以下命令:

xjc -d generated -p net.mycom.tech .

First question is, 第一个问题是

  1. What -b bindings.xjb is meant for? -b bindings.xjb是什么意思? Which content should it has to have? 它必须具有哪些内容? Is it mandatory? 它是强制性的吗?
  2. I'm getting these two kind of error messages: 我收到以下两种错误消息:

    a. 一种。 [ERROR] Two declarations cause a collision in the ObjectFactory class.

    b. b。 A class/interface with the same name "net.mycom.tech.DatosGenericos" is already in use. Use a class customization to resolve this conflict.

My folder is containing several xsd: 我的文件夹包含几个xsd:

在此处输入图片说明

Some help please? 请帮忙吗?

In case of XJC compiler, -b is used for external JAXB binding which overrides the default rule. 对于XJC编译器, -b用于外部JAXB绑定,它将覆盖默认规则。 As an example find below a small snippet. 例如,下面是一个小片段。 The name of this file is mybind.xjb . 该文件的名称是mybind.xjb

<jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    jaxb:extensionBindingPrefixes="xjc">

    <jaxb:globalBindings>
        <xjc:simple />
        <xjc:serializable uid="-1" />
        <jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
            parse="javax.xml.bind.DatatypeConverter.parseDateTime"
            print="javax.xml.bind.DatatypeConverter.printDateTime" />
    </jaxb:globalBindings>
</jaxb:bindings>

In this case mybind.xjb above overrides the dateTime type to the java.util.Calendar type 在这种情况下,上述mybind.xjb会将 dateTime类型覆盖为java.util.Calendar类型

For more details, you can refer below the oracle documentation link. 有关更多详细信息,您可以参考下面的oracle文档链接。 https://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html https://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html

As far the error is concerned, I would recommend to generate the classes to a new directory which is empty. 就错误而言,我建议将类生成到一个空的新目录。 You have to use the following command 您必须使用以下命令

xjc -d src -p com.projectname.place.functionality xmlSchema.xsd

In the above case ensure that the directory src does not contain any java files. 在上述情况下,请确保目录src不包含任何Java文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM