Convert XML to Java Classes

To convert a given XML file to Java Classes we need two tools:

  1. xsd-gen
  2. xjc


xsd-gen is a tool which comes as part of “The Joy of Unix in Windows Tool Bundle”:

Install WizTools and add the location of bin folder to the path C:\Program Files (x86)\WizTools_org\Cli_Tools_Bundle\bin


xjc comes along with jdk and you may find it in jdk bin path. You have to add jdk bin to the path.

Once above tools are set. We can open cmd [command prompt] and enter following command.

xsd-gen xmlFileName.xml > xsdFileName.xsd


This will generate an xsd file which will be used by xjc to convert it to classes.


Once xsd is generated we can use xjc to generate java classes.

xjc -p xsdFileName.xsd


This will create folder structure as per the package specified and necessary java classes inside the folder.