maven-jaxb2-plugin VS jaxb2-maven-plugin for multiple schemas

后端 未结 2 1468
栀梦
栀梦 2021-01-13 05:06

I have multiple xsd schemas that I want to unmarshall into different packages under the same folder target/generated-sources/xjc. I tried both

相关标签:
2条回答
  • 2021-01-13 06:03

    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>
    

    0 讨论(0)
  • 2021-01-13 06:05

    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.

    0 讨论(0)
提交回复
热议问题