简体   繁体   中英

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. 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. In the example below the existing class com.example.Foo will be used for the complex type named Foo .

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 -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.

below is the link for details of the same. 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类)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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