Generating Java beans from a JAXB Schema

To enable you to map to and from XML data and Java™ objects, you can use the JAXB Schema to Java Bean wizard. The wizard generates Java beans that correspond to your schema.

About this task

To generate beans from a JAXB schema, follow these steps:

Procedure

  1. Create one or more Java based projects to work with the beans you will generate from your JAXB schema. For example, create a Java, Web, EJB, or Application Client project. Multiple projects can be used to support schema libraries.
  2. In the Navigator view, right-click the JAXB schema file and click Generate > Java. The Generate Java wizard opens.
  3. From the Generator list, select JAXB Schema to Java Bean. Click Next.
  4. On the Select XML Schema page you have the following options:
    1. Generate schema library: selecting this option will allow you to customize the schema file to project mapping on the next panel.
    2. In the Target Java Container list, specify the project or folder to contain the generated Java beans.
    3. In the Target Package field, type a name for the Java package or accept the default value.
    4. Optional. You can customize the default binding between an XML schema component and its Java representation by adding an external binding declaration. In the Binding Files pane, click Add. Select an external binding declaration file from a location on your machine and click OK. (For example, MyJAXBtoBeanBinding.xjb). The binding compiler uses the binding declarations you specify in the external file to customize your XML to bean bindings without requiring modification to your source schema.
      Note: You can create a binding file using any text editor. The format of your file must conform to the JAXB 2.x specification for external binding declarations.
  5. If you have chosen to generate a schema library, click Next and customize the mappings between XSD documents or groups of XSD documents to a project.
  6. Click Finish. The beans and classes appear in the Navigator view in the location you specified. Double-click them to edit them in the Java or Class editor.
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: jaxbtojava.html