1

Enviroment

I've multiple ant tasks where each of them generates the java code from one XSD for different packages. All tasks are always executed but one after another.

Within those xsds some elements may be defined multiple times but just once per file. Those elements should be placed in different packages. For example:

A_v1.xsd - contains:
         -> <xs:element name="A"> => my.package.a_v1.A.java
A_v2.xsd - contains:
         -> <xs:element name="A"> => my.package.a_v2.A.java

This works fine.

Question

How to translate that into maven?

Problem / What I've tried

I could not create multiple plugin executions in the pom, configure them different and let them run at the same time.

So I tried generating all Java Code from the XSDs in one step but this leads to an exception stating that some fields are already defined.

I also tried to add bindings like:

<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<jxb:bindings schemaLocation="A_v1.xsd" >
    <jxb:schemaBindings>
        <jxb:package name="my.package.a_v1"/>
    </jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="A_v2.xsd" >
    <jxb:schemaBindings>
        <jxb:package name="my.package.a_v2"/>
    </jxb:schemaBindings>
</jxb:bindings>

But the failure is still the same.

Any help will be appreciated! Thanks in advance!

lexicore
  • 42,748
  • 17
  • 132
  • 221
Jan
  • 1,004
  • 6
  • 23
  • 1
    Do these XSDs have the same namespace? – lexicore Aug 14 '18 at 21:25
  • I tried it with different and with no namespaces. Should I declare both for the same namespace? – Jan Aug 15 '18 at 22:22
  • 1
    If your schemas have the same namespace and the same element name, these are, essentially, the same elements. You have to compile these schemas separately then. If these schemas have different namespaces, this should work OOTB. It would be helpful if you provide the full `mvn -X clean install` error log. Which error messages do you get? – lexicore Aug 16 '18 at 13:14
  • Seems I got it. Somehow I had an example defining a namespace within the bindings and I thought that's ok. Seems that didn't work so I checked the XSDs for namespaces and added them. Now everything works fine. Is it somehow possible or does it make sense to define a namespace within the XJB file? Thank you very much for you help! – Jan Aug 16 '18 at 14:02
  • No, namespace definition is an integral part of the schema. – lexicore Aug 16 '18 at 14:31
  • Please add your solution as an answer. So we can vote it up and prevent deletion https://stackoverflow.com/help/deleted-questions – jschnasse Sep 10 '18 at 09:06

1 Answers1

0

With the informations provided by lexicore I identified the XSD files provided simply as incorrect. The old ant build seemed to hide that by building every file separately. In the end adding a namespace to every XSD helped.

Jan
  • 1,004
  • 6
  • 23