3

I have a basic.xsd and two other A.xsd and B.xsd. A.xsd and B.xsd get converted into two different java packages, therefore I need two Maven executions of the same plugin.

Both XSDs refer to basic.xsd for some shared classes. If basic.xsd would come from a different project I could solve this problem really nicely through using episodes to prevent duplicate classes.

But how can I refer to the current project?

My first execution of the plugin is to generate only classes from basic.xsd into its own java namespace. After that the executios of A.xsd and B.xsd should know about the stuff generated from basic.xsd.

Can I somehow point to the generated episode of basic.xsd?

Somehting like

<episodes><episodeFile>basicXSD.episode</episodeFile</episodes> would be nice, but as far as I can see, I can only add dependencies... :-(

Franz Kafka
  • 10,623
  • 20
  • 93
  • 149

2 Answers2

5
<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.8.1</version>
  <executions>
    <execution>
      <id>first</id>
      ...
      <configuration>
        <episodeFile>${some.path}/first.episode</episodeFile>
      </configuration>
    </execution>
    <execution>
      <id>second</id>
      ...
      <configuration>
        <args>
          <arg>-b</arg>
          <arg>${some.path}/first.episode</arg>
        </args>
      </configuration>
    </execution>
  </executions>
</plugin>

http://docs.oracle.com/javase/6/docs/technotes/tools/share/xjc.html http://weblogs.java.net/blog/kohsuke/archive/2006/09/separate_compil.html

Franta Mejta
  • 309
  • 1
  • 5
  • 10
  • This configuration does not generate an episode file for me. Do I need to specify that the first should be an episode @franta-mejta. – mattforni Jan 07 '15 at 23:28
  • @mattforni Episode file should be generated by default. Check your effective-pom if you have `` set to `true`. See https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Episodes for details. – Franta Mejta Jan 08 '15 at 09:27
  • I needed to specify that the execution was an episode, then everything worked fine. – mattforni Jan 16 '15 at 20:08
  • @mattforni , could you please explain when you mean that "you have to specify that the execution was an episode" ? because I have similar issue. – ulab May 20 '16 at 09:15
0

You can simply define two executions of the same plugin like this:

  <plugin>
    <artifactId>maven-whatever-plugin</artifactId>
    <version>1.0</version>
    <executions>
      <execution>
        <id>execution1</id>
        <phase>test</phase>
        <configuration>
         ....
        </configuration>
        <goals>
          <goal>TheGoalYouNeed</goal>
        </goals>
        <phase>process-sources</phase>
      </execution>
      <execution>
        <id>execution2</id>
        <configuration>
           ...
        </configuration>
        <goals>
          <goal>TheGoalYouNeed</goal>
        </goals>
        <phase>process-sources</phase>
      </execution>
    </executions>
  </plugin>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 1
    Yes, but the second and further executions do not use the episode generated from the first execution. You can only define to use episodes from other projects through the use of the `dependency` element. I can let multiple executions run without any problem, but then I get duplicate classes in different namespaces. – Franz Kafka Jun 08 '12 at 15:19
  • Have you checked that with the using of the episode? – khmarbaise Jun 08 '12 at 17:00
  • Furthermore it sounds like you need to define different modules which contains the a.xsd, b.xsd and the base.xsd. – khmarbaise Jun 08 '12 at 17:01