Maven JAXB插件只执行一次执行

时间:2012-08-31 10:21:25

标签: java maven jaxb maven-3 maven-jaxb2-plugin

我正在尝试从两个XSD架构生成源代码。我的JAXB maven插件看起来像这样:

<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
        <execution>
            <id>GenerateKenexa</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <includeBindings>
                    <includeBinding>**/jaxb-bindings-kenexa.xml</includeBinding>
                </includeBindings>
                <includeSchemas>
                    <includeSchema>**/KenexaXMLConfiguration.xsd</includeSchema>
                </includeSchemas>
            </configuration>
        </execution>
        <execution>
            <id>GenerateTalentQ</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <includeBindings>
                    <includeBinding>**/jaxb-bindings-talentq.xml</includeBinding>
                </includeBindings>
                <includeSchemas>
                    <includeSchema>**/TalentQXMLConfiguration.xsd</includeSchema>
                </includeSchemas>
            </configuration>
        </execution>
    </executions>
</plugin>

第一个生成正常。但第二个没有。我在maven输出中看到:

[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateKenexa) @ online.tests.management ---
[INFO] Compiling file:/D:/Projects/GTIWebApplications/gti_online_tests_management/src/main/resources/xsd/KenexaXMLConfiguration.xsd
[INFO] Writing output to D:\Projects\GTIWebApplications\gti_online_tests_management\target\generated-sources\xjc
[INFO] 
[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateTalentQ) @ online.tests.management ---
[INFO] files are up to date

它说文件是最新的,但它们甚至都没有生成。什么可能是错的?

4 个答案:

答案 0 :(得分:12)

对于那些像我一样接受这个问题的人,一年后:/

问题仍存在于maven-jaxb2-plugin中,它可能是0.8.3中的某种错误。 当您将文件生成到同一目录中时,插件&#34;认为&#34;已经生成了文件并跳过了第二次执行。

我发现为了生成第二次执行,你必须设置参数

<forceRegenerate>true</forceRegenerate>

在配置部分。

答案 1 :(得分:4)

我解决了这个问题。我已将maven jaxb插件更改为maven jaxb2插件,现在一切正常。现在我的maven配置如下所示:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.2</version>
    <executions>
        <execution>
            <id>GenerateKenexa</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                <schemaIncludes>
                    <include>KenexaXMLConfiguration.xsd</include>
                </schemaIncludes>
                <generatePackage>com.groupgti.onlinetest.kenexa.jaxb</generatePackage>
                <generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>
            </configuration>
        </execution>
        <execution>
            <id>GenerateTalentQ</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                <schemaIncludes>
                    <include>TalentQXMLConfiguration.xsd</include>
                </schemaIncludes>
                <generatePackage>com.groupgti.onlinetest.talentq.jaxb</generatePackage>
                <generateDirectory>${project.build.directory}/generated-sources/talentq</generateDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

答案 2 :(得分:1)

首先,我建议为每个xsd <outputdirectory>${basedir}/target/generated-sources/xjc</outputdirectory>

指定单独的输出文件夹

第二,尝试将其设置为单独的插件条目,而不是单独的执行:

<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/KenexaXMLConfiguration.xsd...
...
</plugin>
<plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/TalentQXMLConfiguration.xsd...
...
</plugin>

答案 3 :(得分:1)

当我到达这里时,我正在使用jaxb2,但仍然面临着问题。我从其他人的答案中将下面的部分添加到配置中,现在可以使用了。 对于以前的答案,完成这个技巧的部分应该是:

<generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>

还需要一个唯一的执行ID

<id>GenerateKenexa</id>

但不同的目录使代码分为两个顶级包,所以最后我使用:

<forceRegenerate>true</forceRegenerate>