Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB, XJC -> create multiple class files

Tags:

java

xml

jaxb

xjc

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

like image 240
Olivier J. Avatar asked Nov 01 '12 10:11

Olivier J.


People also ask

How do I use JAXB XJC?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.

What is JAXB XJC?

JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances. JAXB technology consists of a runtime API and accompanying tools that simplify access to XML documents.

What is XJB file in JAXB?

xjb extension to resolve any conflicts in the WSDL or schema. For example if two elements have the same name and you want to distinguish between them you can rename one by specifying it the bindings file.


1 Answers

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

  • http://blog.bdoughan.com/2011/07/jaxb-xjc-and-nested-classes.html
like image 122
bdoughan Avatar answered Sep 23 '22 21:09

bdoughan