Search code examples
javamavenjaxbxjcmaven-jaxb2-plugin

JAXB Maven generate classes using multiple episodes


Using this maven plugin, I was able to generate my classes and reused them in another schema; which is really great!

Now I find myself with a schema needing two episodes (two different packages generated from schemas). I simply tried to add another arg in XJC, but it didn't work.

Then I changed the order of the two args, and the error targetted the other schema. I then understood that both episodes were OK, but it might not be the way of doing things.

Here is some of my pom:

<execution>
    <id>business</id>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
      ..
      <extension>true</extension>
      <args>
        <arg>-b</arg>
        <arg>${project.basedir}/target/episodes/x.episode</arg>
        <arg>${project.basedir}/target/episodes/y.episode</arg>
        <arg>${project.basedir}/target/episodes/z.episode</arg>
      </args>
      ..
    </configuration>
</execution>

And here is what I get:

org.xml.sax.SAXParseException; systemId: file:/****.episode; lineNumber: 2; columnNumber: 65; s4s-elt-schema-ns: namespace element 'bindings' must be from 'http://ww.w3.org/2001.XMLSchema'.

From what I understand (after swapping their call in ), the three schemas/episodes are good, but I cannot use them both at the same time. Any way to do that?

Newbie here, any help much appreciated :).


Solution

  • Author of the here.

    Why do you use args, why not just add your episodes in the configuration?

    <episodes>
        <episode>
            <groupId>com.acme.foo</groupId>
            <artifactId>package1</artifactId>
            <!-- Version is not required if the artifact is
                configured as dependency -->
        </episode>
        <episode>
            <groupId>com.acme.foo</groupId>
            <artifactId>package2</artifactId>
            <!-- Version is not required if the artifact is
                configured as dependency -->
        </episode>
    </episodes>
    

    The whole idea of episodes is that you can point to the JAR (containing the episode file) and XJC will find out and use the binding from the contained episode. Using arg with -b is not what it was inteded for. :)

    Concerning the error you're seeing, I guess the way you configure arg makes XJC think that your second and further episodes are actually schemas. I'd try to put intermediate -b arguments or configure all the episodes you refer to in one arg.

    But I still think it is not the right way to use episodes. Compile your episodes as separate JARs/separate Maven modules, use them as dependencies and either configure them as episodes or just turn on the useDependenciesAsEpisodes option.