1

我正在制作一个 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]

但是,如果我像下面这样评论源代码并取消评论和修改,那么我就可以从常见的模式中生成 java 类。

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

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

谢谢

4

1 回答 1

0

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

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

于 2019-12-13T17:39:58.053 回答