我正在制作一个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>
有谁能告诉我为什么这样做?如果我必须解析一个根文件夹(有多个子文件夹)下的所有模式文件,该怎么办?
由于
答案 0 :(得分:0)
该插件的1.6版不支持“ sources”标签。您可以在2.4版或更高版本上使用“ sources标签。
如果您有多个包含xsds的目录,请在配置中使用多个执行,每个schemaDirectory指向您的目录之一。