filmac
filmac

Reputation: 197

JAXB-2 Maven Plugin, schema inclusion and bindings

I am using JAXB-2 Maven Plugin to generate java classes starting from some xsd files. My configurations is the following. I have three schema files without target namespace A included by B included by C and then I have two others schemas D and E with a provided namespace, both of them including C. Is it possible to use bindings or different executions (with episodes) to have each schema producing classes in a different packages? Something like:

A schema (no namespace) -> com.packageA
B schema (no namespace) -> com.packageB
C schema (no namespace) -> com.packageC
D schema (namespace X) -> com.packageD
E schema (namespace X) -> com.packageE

of course without classes duplication? Or the best I can have is to have two packages, one for classes belonging to XSDs files with the empty namespace and one for the two XSDs files with the namespace X? Could you please provide an example of pom.xml file to achieve that? Thanks And how can

Upvotes: 1

Views: 2281

Answers (1)

lexicore
lexicore

Reputation: 43671

Disclaimer: I'm the author of maven-jaxb2-plugin so this answer is about that plugin.

This is called "separate schema compilation". This can be achieved using episodes, see the explanation in the maven-jaxb2-plugin docs.

In short:

  • Create one Maven project per logical schema. I normally have one project per distinct namespace.
  • If schema B uses schema A, include artifact of schema A as dependency of B.
  • maven-jaxb2-plugin will use dependencies as episodes by default.
  • In some cases some restover classes are still generated for included episodes. They should not be, I believe it is a bug in XJC. In those cases, add clean-up task.
  • Be ready to face a number of weird problems as XJC is a tricky tool.

Here's a project which compiles a huge set of schemas in this fashion. The result is some 100+ artifacts with dependencies closely resembling dependencies of schemas.

One problem which I see is that you have schemas A, B and C having the same (empty) namespace, mapping to different packages. This may not work well with JAXB (see also "chameleon namespaces").

Upvotes: 1

Related Questions