Documentation is available here: http://confluence.highsource.org/display/J2B/JAXB2+Basics+Plugins
This simple example generates my_schema.xsd JAXB classes and puts them into src/main/java in the com.me.generated package. This is pretty much the most simple example of this plugin.
Example With Catalogue File<plugin>
This plugin will parse the available *.xsd files in the src/main/resources directory and create JAXB annotated classes in the src/main/java directory. If an bindings.xjb is also present in the resources directory then this will be used.
generateDirectory - where to put the JAXB classes.
catalogs - These allow an xsd reference to be overridden and redirected locally or into a jar file.
episodes - This tells xjc to not create code for these xsd because it is already available.
episode - This tells xjc to generate an episode file for these xsds
args - optional arguments to add to the JAXB classes. This requires the plugin that follows it.
Catalog FileA catalog file allows the xsd schema locations to be altered and redirected. If a schema file has an import such as
<xs:import namespace="http://www.me.com/common/config" />
Note there is no schemaLocation value. This will fail the schema validation without a catalog file helping to tell xjc where the actual xsd source is. A valid catalog file to do this would be
PUBLIC "http://www.me.com/common/config" "maven:com.me.common:xsd-project!/config.xsd"
Here the first part of the catalog has the same namespace as the import namespace. This is how they match. The second element can be a standard file location or, like here, a reference to an xsd in a jar which is a maven dependency. It is only with the maven plugin that this maven:... reference will work. Standard xjc does not recognise this notation. NOTE: there is a colon separating 'maven' from the groupId from the artifactId. Putting a . instead will cause the catalogue redirect to not work and that can eat up time trying to find the reason why!!
Episode FileAn episode file is just a standard bindings file. It tells xjc not to create JAXB annotated classes for objects which may appear in an xsd (Not all the elements of the xsd need to be contained in an episode file although this would be a little unusual and require manually changing the episode file after generation).
This maven plugin can use episode files from other jars but can also be told to generate one using the
Common ErrorsIf you get a stack trace like this,
com.sun.istack.SAXParseException2: SCD "x-schema::tns" didnt match any schema component
Then a schema is included in the episode file but never referenced. If you can remove the episode file from the configuration then this will cure it. Otherwise just create an empty schema which imports all the episode elements but does nothing with them. I think this error is trying to be helpful and tell you when something is included and it doesn't need to be but the message isn't particularly clear. Hopefully there may be an option to ignore this error in the future because an episode file may contain multiple schemas when you don't necessarily need them all.