Generating java classes from xml schema using maven

While I was working on a SOA project I thought about how to handle xml schema files (xsds) the best way in maven. Since maven offers semantic versionig it would be nice to use this mechanism for xsds as well.

So i set up some sample projects to find it out.

The easiest way to add a xml schema to maven ist to use the maven install and maven deploy plugin like this:

The above command simply adds the xsd as a maven artifact. It is now accessible by its version.

But the questions came up, how this xml schema can be referenced as a maven dependency to generate java sources from it.

Actually declaring the xsd as a dependency of a project’s pom is quiet simple:

When using the maven dependency plugin to copy all dependencies, the xsd is actually copied to the output directory:


This verifies that the artifact is correctly referenced an found (in this case) in the local repository.

The next step was to get this jaxb maven plugin to pick it up and create java sources from it. This plugin allows for adding maven arifacts that contain xsds to be used as the source for code generation (see also this link). So I added the dependency like this to the plugin configuration:

Unfortunately that did not work and I haven’t found a solution for that problem to this very day. Maybe I have to try a different syntax for the it to work.

For the time being I decided to put my xsds into a plain java maven project as a resource:

Then I added the schemas to the plugin’s configuration:

This works even with the somewhat shorter url notation:

Nevertheless would it be nice to actually see the first approach working. So if I find the time I will be digging a little bit deeper into this issue.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">