简体   繁体   中英

Generate Java from multiple xsd files with xjc

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM