【问题标题】:Generating classes using multiple xsd schema with duplicate class entry使用具有重复类条目的多个 xsd 模式生成类
【发布时间】:2016-04-04 09:22:47
【问题描述】:

我有多个 xsd 架构文件,其中包含多个/常见的重复 xs:element / class 条目。我尝试使用 pom.xml 中的以下行将它们转换为类

<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>schema1</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>src/main/resources/xsd/schema1</schemaDirectory>
                            <schemaIncludes>
                                <include>schema1.xsd</include>
                            </schemaIncludes>
                            <packageName>com.schema1.rest.stub</packageName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>schema2</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>src/main/resources/xsd/schema2</schemaDirectory>
                            <schemaIncludes>
                                <include>schema2.xsd</include>
                            </schemaIncludes>
                            <packageName>com.schema2.rest.stub</packageName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

虽然只使用一个 execution 标记运行,但我正在成功获取课程。但是当我包含两个或两个以上架构或execution 标记时,我只能看到为最后一个架构“schema2”创建的类,而不是为“schema1”创建的类。

在命令行日志中运行时,我可以看到为这两个模式生成了类。但结果是删除旧包并重新创建它。基本上我只有最后一个模式的类,而不是其他模式。

我该如何解决?

【问题讨论】:

    标签: java maven xsd xjc jaxb2-maven-plugin


    【解决方案1】:

    在两个&lt;configuration&gt; 标记中使用&lt;clearOutputDir&gt;false&lt;/clearOutputDir&gt;

    例如:

    <configuration>
        <clearOutputDir>false</clearOutputDir>
        <schemaDirectory>src/main/resources/xsd/schema2</schemaDirectory>
        <schemaIncludes>
            <include>schema2.xsd</include>
        </schemaIncludes>
        <packageName>com.schema2.rest.stub</packageName>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      相关资源
      最近更新 更多