Skip to Content
Technical Articles
Author's profile photo stephen xue

Two tips on using JAXB

If you are totally new to JAXB, please refer to

1         XSD has “import”, “include”


  • Import has to be from another namespace;
  • Include has the same namespace;


When XSD file, like common, has types as below:

Get error like below in the console while generating classes from XSD by using JAXB


Place all of the relevant xsd files into one folder

Please get all of the sample XSD files from Github and load them into eclipse. (this is my first time use Github. if you have difficult download the files, please let me know)

Here is the view from the eclipse

Create the class from schema by using the usual way

Get these logs in the console

All of the relevant classes will be listed below

2. Create class from simple type

By default, the JAXB will only generate class from complex types of the schema. If the simple types are intended to be converted into class, a special binding file has to been created.

<bindings version="2.0" xmlns=""
            <globalBindings mapSimpleTypeDef="true"/>

copy paste the above code and create a file with name: bingdings.xjb

It can be downloaded from Github as well.

Place the file in the package folder

Generate class from schema as below

In the step below, choose the xjb from the folder

This is the view after clicking OK button

By clicking the Finish button, all of the types will be created into java classes

Compare with the list in the last section, we can see there are more classes generated. Actually all classes have been generated from both complex types and simple types in the schema.


Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.