maven-jaxb2-plugin用于多个模式的VS jaxb2-maven-plugin

时间:2014-03-20 19:25:29

标签: java eclipse maven maven-jaxb2-plugin jaxb2-maven-plugin

我有多个xsd架构,我想在相同文件夹target/generated-sources/xjc下解组到不同的包中。我尝试了两个插件,两者似乎都能正常使用这两种配置但是在maven-jaxb2-plugin的情况下,eclipse插件会无限期地生成类(因为forceRegenerate = true)但是如果我不这样做的话指定forceRegenerate当我运行mvn clean package时,它根本不会生成第二和第三组类吗?我的配置是否有任何问题?

JAXB2-行家-插件

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

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

2 个答案:

答案 0 :(得分:3)

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

<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的问题。我会看看它。

PS。免责声明:我是maven-jaxb2-plugin的作者。

答案 1 :(得分: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>