I'm using JAXB and XJC for first time.
I would like to generate Java classes from XML file so I use this online helper to generate schema from XML file.
After that I just use this command line to generate Java classes :
xjc myschema.xsd
it's work but I receive only one Java file and many static classes inside it. Is this possible to generate many java files that contain only one classe per file please ?
Thank you
By default JAXB (JSR-222) will create static inner classes for nested complex types to prevent class name conflicts. You can use an external binding file to disable this behaviour.
binding.xml
A binding file allows you to customize how Java classes are generated from an XML schema.
<jaxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jaxb:globalBindings localScoping="toplevel"/>
</jaxb:bindings>
XJC Call
The -b
option is used with the XJC command to specify a binding file.
xjc -b binding.xml myschema.xsd
For More Information