6

我有多个 xsd 模式,我想将它们解组到同一文件夹下的不同包中target/generated-sources/xjc。我尝试了这两个插件,并且似乎都可以很好地使用这两种配置,但是在 maven-jaxb2-plugin 的情况下,eclipse 插件会无限期地生成类(因为forceRegenerate= true)但是如果我不指定 forceRegenerate 它不会生成当我运行第二组和第三组类时mvn clean package我的配置有什么问题吗?

jaxb2-maven-插件

<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>
<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>

和 build-helper-maven-plugin 配置:

<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>
4

2 回答 2

3

一般建议:bindings.xjb在不同的执行中指定您的包,而不是使用单独generatePackage的 s.

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

generatePackage不能很好地与多个模式一起使用。

请在

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

引用多个模式和 Eclipse 的问题。我会看看它。

附言。所以免责声明:我是maven-jaxb2-plugin.

于 2014-03-21T12:42:16.780 回答
1

我的解决方案:

<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>

于 2015-01-20T16:16:28.487 回答