jaxb2 maven插件和执行标记内的配置

时间:2011-11-04 06:36:48

标签: configuration maven jaxb2

我尝试使用JAXB2 maven插件从一堆.xsd文件生成java代码。如果我尝试在一次执行中从所有xsds生成,我将获得org.xml.sax.SAXParseException: 'root' is already defined。我无法修改xsd文件,所以我需要独立生成每个文件。我找到了以下pom配置来实现:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
    <execution>
        <id>jaxb-Execution1</id>
        <phase>generate-sources</phase>
        <goals><goal>xjc</goal></goals>
        <configuration>
            <schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
            <outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
            <staleFile>${jaxbGenerateDirectory}/.staleFlagExecution1</staleFile>
            <bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
            <bindingFiles>bindings1.xml</bindingFiles>
            <schemaFiles>schema1.xsd</schemaFiles>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
    <execution>
        <id>jaxb-Execution2</id>
        <phase>generate-sources</phase>
        <goals><goal>xjc</goal></goals>
        <configuration>
            <schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
            <outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
            <staleFile>${jaxbGenerateDirectory}/.staleFlagExecution2</staleFile>
            <bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
            <bindingFiles>bindings2.xml</bindingFiles>
            <schemaFiles>schema2.xsd</schemaFiles>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
</executions>

但这不起作用。问题是不从执行块内部读取配置。这是为什么?我正在使用maven 2.2.1。

1 个答案:

答案 0 :(得分:2)

当我尝试使用以下命令运行插件时遇到了同样的问题:

mvn jaxb2:xjc

我的解决方法是使用:

mvn generate-sources