mvn-scalaxb: Running scalaxb from Maven

Running scalaxb from Maven

The scalaxb-maven-plugin is provided to allow scalaxb to be run as part of a maven build.

Step 1: Add the plugin to the pom.xml

Add the following plugin definition to your pom.xml file, and change the packageName from 'ipo' to something more suitable for your project.


For more information about the available configuration parameters, see:

Note: The plugin is called scalaxb-maven-plugin, and not maven-scalaxb-plugin. This is consistent with the Maven convention that only plugins from Apache are named maven-xxx-plugin, but can seem inconsistent to those accustomed to just using the standard set of plugins.

For more help on the available configuration parameters, run:

mvn org.scalaxb:scalaxb-maven-plugin:help -Dgoal=generate -Ddetail

Step 2: Add your XSD files in src/main/xsd

By default, the scalaxb maven plugin looks for XSD files in src/main/xsd, so the simplest thing is to put your XSD files in there.

Step 3: Run scalaxb to generate code from your XSD

To generate the Scala sources from the XSD files, run:

    mvn generate-sources

The Scala sources will be generated in target/generated-sources/scalaxb when Maven runs the generate-sources phase of the lifecycle. This might be done automatically by your IDE.

There's no need to do this step if you're running a later phase in the Maven lifecycle anyway. For example, if you run mvn compile, there's no need to invoke mvn generate-sources beforehand.

That's it!