【问题标题】:Jaxb2 maven plugin : Sources vs SchemaDirectoryJaxb2 maven 插件:Sources vs SchemaDirectory
【发布时间】:2019-12-14 02:56:24
【问题描述】:

我正在制作一个 maven 项目,该项目将利用 Jaxb2-maven-plugin 从 xsd 文件生成 java 文件。我的项目结构是这样的:

project.basedir
--src/main/resources/schemas
----common
----request
----response

下面是 pom.xml 中的插件配置

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.6</version>

    <executions>
        <execution>
            <id>xjc-PDF</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <extension>true</extension>
                <clearOutputDir>false</clearOutputDir>
                <outputDirectory>${project.build.directory}/generated-sources/jaxb</outputDirectory>
                <explicitAnnotation>true</explicitAnnotation>
                <!-- <schemaDirectory>${project.basedir}/src/main/resources/schemas</schemaDirectory> -->
                <sources>
                    <source>${project.basedir}/src/main/resources/schemas/common</source>
                    <source>${project.basedir}/src/main/resources/schemas/response</source>
                    <source>${project.basedir}/src/main/resources/schemas/request</source>
                </sources>
                <bindingDirectory>${project.basedir}/src/main/resources/schemas</bindingDirectory>
                <!-- <bindingDirectory>${project.basedir}/src/main/resources/bindings</bindingDirectory> -->
                <bindingFiles>jaxb-bth.xjb</bindingFiles>
            </configuration>
        </execution>
    </executions>
</plugin>

如果我这样编译,则会出现以下错误(即使源目录包含有效的模式文件):

C:\ESB_SOAP5_Space\pdf-util>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pdf-util 1.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pdf-util ---
[INFO] Deleting C:\ESB_SOAP5_Space\pdf-util\target
[INFO]
[INFO] --- build-helper-maven-plugin:1.6:add-source (add-source) @ pdf-util ---
[INFO] Source directory: C:\ESB_SOAP5_Space\pdf-util\target\generated-sources\jaxb added.
[INFO]
[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc-PDF) @ pdf-util ---
[INFO] Generating source...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.205 s
[INFO] Finished at: 2018-03-19T06:27:02+11:00
[INFO] Final Memory: 8M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc (xjc-PDF) on project pdf-util: No schemas have been found -> [Help 1]

但是,如果我像下面那样注释源并取消注释和修改,那么我可以从 common 下的模式生成 java 类。

<schemaDirectory>${project.basedir}/src/main/resources/schemas/common</schemaDirectory> 

谁能告诉我为什么会这样?另外,如果我必须解析一个根文件夹(有多个子文件夹)下的所有架构文件,我该怎么办?

谢谢

【问题讨论】:

    标签: maven jaxb2-maven-plugin


    【解决方案1】:

    1.6 版插件不支持“来源”标签。您可以在 2.4 或更高版本上使用“sources 标签”。

    如果您有多个包含 xsd 的目录,请在配置中使用多个执行,每个 schemaDirectory 指向您的目录之一。

    【讨论】:

      猜你喜欢
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-13
      • 1970-01-01
      相关资源
      最近更新 更多