maven-jaxb2-plugin: how to accomplish this xjc command-line in the pom.xml?

4.9k views Asked by At

Because of various issues with the XSDs I need to compile (described in other SO posts), I have a bindings file and also a local extension schema. The following command line works correctly, but I'm having trouble figuring out the right pom.xml configuration to mimic this:

xjc -nv src/main/resources/TCIP_4_0_0_Final.xsd src/main/resources/local/ObaCcLocationReport.xsd -b src/main/resources/local/rename.xjb -d target

Mainly, how do I specify more than one XSD? I tried:

<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
  <include>TCIP_4_0_0_Final.xsd</include>
  <include>local/ObaCcLocationReport.xsd</include>
</schemaIncludes>

but it seemed to ignore the second include.

I also tried variations on:

<schema>
  <fileset>
    <directory>src/main/resources</directory>
    <includes>
      <include>TCIP_4_0_0_Final.xsd</include>
      <include>local/ObaCcLocationReport.xsd</include>
    </includes>
  </fileset>
</schema>

without success. Suggestions?

EDIT

This works as a workaround, but it's not ideal:

Since ObaCcLocationReport.xsd depends on schemas that get compiled as part of TCIP_4_0_0_Final.xsd, I just had to make sure it got compiled after that, and it seems to process files in filepath order. So I put the ObaCcLocationReport.xsd into an x subfolder and changed the pom.xml to:

<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
  <include>TCIP_4_0_0_Final.xsd</include>
  <include>x/ObaCcLocationReport.xsd</include>
</schemaIncludes>

This compiled the schemas and generated the Java files correctly.

1

There are 1 answers

2
lexicore On

Disclaimer: I am the author of the maven-jaxb2-plugin.

So your compilation depends on the order of the schema files in the XJC command? Hm, interesting. Why?

Please post mvn -X clean generate-sources log in such cases.

It really seems that Maven does not maintain the order of the file patterns as I also get:

schemas=[file:/.../src/main/resources/local/ObaCcLocationReport.xsd,
         file:/.../src/main/resources/TCIP_4_0_0_Final.xsd]

Which is not what you want. Can be fixed, please file an issue. (I rely on one of the Maven libraries here, but can do it differently to maintain the order.)

You can configure it as follows:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <strict>false</strict>
                <schemaIncludes/>
                <schemas>
                    <schema>
                        <fileset>
                            <includes>
                                <include>TCIP_4_0_0_Final.xsd</include>
                            </includes>
                        </fileset>
                    </schema>
                    <schema>
                        <fileset>
                            <includes>
                                <include>local/ObaCcLocationReport.xsd</include>
                            </includes>
                        </fileset>
                    </schema>
                </schemas>
            </configuration>
        </execution>
    </executions>
</plugin>

Gives you:

schemas=[file:/.../src/main/resources/TCIP_4_0_0_Final.xsd,
         file:/.../src/main/resources/local/ObaCcLocationReport.xsd]

Notes:

  • Don't forget <schemaIncludes/> otherwise src/main/resources/*.xsd will be included by default.
  • <strict>false</strict> gives you -nv.
  • You can always do args/arg to configure xjc on the low level, but I won't recommend it.