IntroductionJAXB2 Basics is an open source project which implements plugins and tools for JAXB 2.x reference implementation. JAXB2 Basics is a part of JAXB2 Commons project.
JAXB RI contains a schema compiler called XJC. One of the most important features of XJC is extensibility. You can implement your own XJC plugins to enhance, modify or customize the generated code. See this blog entry for a short introduction.
Using JAXB plugins in your builds
In order to use JAXB plugins in your builds, you essentially need to make two things:
- Add the plugin library available into the XJC classpath (including all the required dependencies).
- Activate (and possibly configure) the plugin by adding corresponding command-line arguments.
Following section describe how this can be done with Ant and Maven. Check sample projects for working examples.
Using JAXB plugins with Ant
Assume your libraries (
*.jar files) are placed in the
lib directory. Below is the possible code generation target of an Ant build script:
In Ant builds, plugin libraries are provided to XJC via the
xjc/classpath element. Note that I had to list the plugin library (
jaxb2-basics-*.jar) as well as all of its dependencies (
jaxb2-basics-runtime-*.jar and so on).
Plugins are activated using the
@line attribute of the
You can also use this element to provide configuration to the plugins that you use:
Using JAXB plugins with Maven
In Maven builds, you have to list your JAXB plugin artifacts in
configuration/plugins/plugin elements (you don't need to define the dependencies, Maven will take care of dependency resolution). JAXB plugins are activated and configured via the