简体   繁体   English

如何使用一些现有的Java类使用XJC生成JAXB类?

[英]How to generate JAXB classes using XJC using some existing Java classes?

The scenario is I have a bunch of schemas in .xsd format, which I can generate using XJC. 场景是我有一堆.xsd格式的模式,我可以使用XJC生成。 However, I do not like one of the class generated using this approach, as a result, I would like to manually curate a replacement for that specific class. 但是,我不喜欢使用这种方法生成的类之一,因此,我想手动策划该特定类的替换。 That class is being referenced by other classes in the schema. 该类正被架构中的其他类引用。 Is there a way of doing that? 有没有办法做到这一点?

You can use an external binding file to configure XJC to do what you want. 您可以使用外部绑定文件将XJC配置为执行您想要的操作。 In the example below the existing class com.example.Foo will be used for the complex type named Foo . 在下面的示例中,现有的类com.example.Foo将用于名为Foo的复杂类型。

binding.xml binding.xml

<jxb:bindings schemaLocation="yourSchema.xsd">
    <jxb:bindings node="//xs:complexType[@name='Foo']">
        <jxb:class ref="com.example.Foo"/>
    </jxb:bindings>
</jxb:bindings>

XJC Call XJC电话

xjc -d outputDir -b binding.xml yourSchema.xsd

You can manually create the class you have to use jaxb annotaion from javax.xml.bind.annotation package in you class. 您可以手动创建必须在您的类中使用javax.xml.bind.annotation包中的jaxb annotaion的类。

below is the link for details of the same. 以下是相同细节的链接。 http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/package-summary.html http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/package-summary.html

but if you can be more specific to your question like what you didnt like in autogenerated classes like class name or package name or anything else that will be a great help to answer this question. 但是如果你可以更具体地解决你的问题,比如你不喜欢自动生成的课程,比如班级名称或包名或其他任何能帮助回答这个问题的人。

只要您使用相同的值注释字段/属性,就可以手动更改类并更改任何引用(包括ObjectFactory类)。

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

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