【问题标题】:Can I include java source from multiple projects when running schemagen using the jaxb2-maven-plugin?使用 jaxb2-maven-plugin 运行 schemagen 时,我可以包含来自多个项目的 java 源吗?
【发布时间】:2013-04-11 10:21:41
【问题描述】:

我有一个多模块 maven 项目,我需要从带有 JaxB 注释的类构建 XML 模式。这些类位于不同的 Maven 项目中。我可以使用 jaxb2-maven-plugin 通过指向所有项目的源来生成单个模式吗?或许是这样的……

<configuration>
    ...
    <includes>    
        <include>../OtherProj1/src/main/java/**/*.java</include>
        <include>../OtherProj2/src/main/java/**/*.java</include>
        <include>**/*.java</include>
    </includes>
    ...
</configuration>

或者我是否需要为每个项目单独创建一个架构,然后将它们导入到父架构中?

我正在使用 maven 2.2.1 和 jaxb2-maven-plugin 1.3。

【问题讨论】:

  • 我可以通过恢复到 maven-antrun-plugin 并调用 schemagen 任务来完成这项工作,但如果可能的话,我真的很想使用 jaxb2-maven-plugin。
  • 您好 RJC,您解决了这个问题吗?我有相同的问题。我想从 src/main/java 以外的地方添加 .java 文件
  • @WhiteRoses - 我不得不使用 antrun 插件。我已经为此发布了我的配置。希望对您有所帮助。

标签: java maven-2 jaxb2 schemagen jaxb2-maven-plugin


【解决方案1】:

我认为 antrun 插件是包含来自 mvn 项目外部的源代码以生成 XML 模式的唯一方法。

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <configuration>
                <target>                        
                    <taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask">
                    </taskdef>
                    <schemagen destdir="src/main/resources/" includes="<comma separated paths to include>"
                        excludes="<comma separated paths to exclude>">
                        <src path="src/main/java" />
                        <src path="../OtherProj1/src/main/java" />
                        <src path="../OtherProj2/src/main/java" />                  
                    </schemagen>
                    <move file="src/main/resources/schema1.xsd" tofile="src/main/resources/<filename>.xsd" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 2010-11-16
    • 2017-06-15
    相关资源
    最近更新 更多