maven-jaxb2-plugin VS jaxb2-maven-plugin for multiple schemas
Asked Answered
C

2

7

I have multiple xsd schemas that I want to unmarshall into different packages under the same folder target/generated-sources/xjc. I tried both plugins and both seem to work fine with these 2 configurations but in case of maven-jaxb2-plugin the eclipse plugin keeps generating classes indefinitely (because of the forceRegenerate = true) but if I don't specify forceRegenerate it won't generate the second and third set of classes at all when I run mvn clean package Are there any issues with my configuration?

jaxb2-maven-plugin

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
    <execution>
        <id>xjc-scores</id>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.scores</packageName>
            <schemaDirectory>src/main/resources/schemas/scores</schemaDirectory>
        </configuration>
    </execution>
    <execution>
        <id>xjc-videos-ramp</id>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.ramp</packageName>
            <schemaDirectory>src/main/resources/schemas/ramp</schemaDirectory>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
    <execution>
        <id>xjc-schedules</id>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.schedules</packageName>
            <schemaDirectory>src/main/resources/schemas/schedules</schemaDirectory>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
</executions>
<configuration>
</configuration>
</plugin>

maven-jaxb2-plugin

<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
    <execution>
        <id>xjc-scores</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <generatePackage>com.generated.scores</generatePackage>
            <schemaDirectory>src/main/resources/schemas/scores</schemaDirectory>
            <removeOldOutput>true</removeOldOutput>
        </configuration>
    </execution>
    <execution>
        <id>xjc-ramp</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <generatePackage>com.generated.ramp</generatePackage>
            <schemaDirectory>src/main/resources/schemas/ramp</schemaDirectory>
            <removeOldOutput>false</removeOldOutput>
        </configuration>
    </execution>
    <execution>
        <id>xjc-schedules</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <generatePackage>com.generated.schedules</generatePackage>
            <schemaDirectory>src/main/resources/schemas/schedules</schemaDirectory>
            <removeOldOutput>false</removeOldOutput>
        </configuration>
    </execution>
</executions>
<configuration>
    <forceRegenerate>true</forceRegenerate>
</configuration>
</plugin>

and the build-helper-maven-plugin config:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
    <execution>
        <id>add-source</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>add-source</goal>
        </goals>
        <configuration>
            <sources>
                <source>target/generated-sources/xjc</source>
            </sources>
        </configuration>
    </execution>
    <execution>
        <id>add-resource</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>add-resource</goal>
        </goals>
        <configuration>
            <resources>
                <resource>
                    <directory>target/generated-sources/xjc</directory>
                    <targetPath>target/classes</targetPath>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>
</plugin>
Cannibal answered 20/3, 2014 at 19:25 Comment(0)
E
3

General advice: specify your packages in bindings.xjb rather than in different executions with individual generatePackages.

<jxb:bindings schemaLocation="common1.xsd" node="/xsd:schema">
    <jxb:schemaBindings>
        <jxb:package name="mypackage.commonclasses"/>
    </jxb:schemaBindings>
</jxb:bindings>

generatePackage does not really work well with multiple schemas.

And please file a bug in

https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN

citing the problem with the multiple schemas and Eclipse. I'll take a look into it.

ps. SO disclaimer: I'm the author of maven-jaxb2-plugin.

Engird answered 21/3, 2014 at 12:42 Comment(2)
Thank you for the tip on the package declaration. I filed a ticket for your review. BUGCannibal
@Cannibal I failed to reproduce it, see here: github.com/highsource/maven-jaxb2-plugin/tree/master/tests/… Could you please check if the problem still persists?Engird
S
2

My solution:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
    <execution>
        <id>xjc-scores</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.scores</packageName>
          <schemaDirectory>src/main/resources/schemas/scores</schemaDirectory>
            <clearOutputDir>true</clearOutputDir>
        </configuration>
    </execution>
    <execution>
        <id>xjc-videos-ramp</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.ramp</packageName>
            <schemaDirectory>src/main/resources/schemas/ramp</schemaDirectory>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
    <execution>
        <id>xjc-schedules</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.schedules</packageName>
          <schemaDirectory>src/main/resources/schemas/schedules</schemaDirectory>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
</executions>

Somerville answered 20/1, 2015 at 16:16 Comment(1)
Any more configuration? Or is the plugin node described completely in the snippet? I'm still getting "No schemas have been found".Hamilton

© 2022 - 2024 — McMap. All rights reserved.