xjc – Convert XML Schema to Java

Introduction

The xjc tool generates Java source code from an XML Schema. This article is a quick reference page to use xjc from both the command line and Maven.

This reference page is part of a series of articles on JAXB:

Command Line Syntax

The xjc syntax below generates the Java source code from the company.xsd file.

You need to ensure the src directory exists, as otherwise nothing will happen.

And this is it! For more details check the official documentation.

Maven

If you use maven, you can use the JAXB-2 Maven Plugin to generate Java source. This is how you declare the plugin in the pom.xml file:

The source parameter above determines the location of the .xsd file. It will process all .xsd files in the src/main/resources/examples/xjc directory. If you have .xsd files in multiple locations, then just add another source entry. The packageName parameter determines the package of the sources generated. It overrides any package level annotations declared in the .xsd files.

Bibliography

The following two tabs change content below.

Eduard Manas

Eduard is a senior IT consultant with over 15 years in the financial sector. He is an experienced developer in Java, C#, Python, Wordpress, Tibco EMS/RV, Oracle, Sybase and MySQL.Outside of work, he likes spending time with family, friends, and watching football.

Latest posts by Eduard Manas (see all)

Leave a Reply