[英]jaxb2-maven-plugin - how to turn off recursive directory traversal when generating xsd from classes
I am using jaxb2-maven-plugin for generating XSD from jaxb annotated classes. 我正在使用jaxb2-maven-plugin从jaxb注释类生成XSD。
The configuration looks like that 配置看起来像这样
<execution>
<id>rest-api-execution-schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<sources>
<source>src/java/foo/rest/execution/model</source>
</sources>
<outputDirectory>${project.build.directory}/execution-api-xml-schema</outputDirectory>
</configuration>
</execution>
The package foo/rest/execution/model contains many classes, that is why I wish to avoid listing all of them in separate <source>
elements. 软件包foo / rest / execution / model包含许多类,这就是为什么我希望避免在单独的
<source>
元素中列出所有它们的<source>
。 Instead, I specified that I wish to include the whole src/java/foo/rest/execution/model
directory, using a single <source>
element. 相反,我指定我希望使用单个
<source>
元素包括整个src/java/foo/rest/execution/model
目录。
The problem is that there are subpackages: 问题是有子软件包:
foo/rest/execution/model/builder
... which contain other classes that are not jaxb annotated and should not be part of the schema. ...包含其他未用jaxb注释的类,因此不应成为架构的一部分。 Unfortunately, the schemagen goal attempts to traverse the foo/rest/execution/model directory recursively and therefore attempts to generate schemas for the classes in the subdirectories.
不幸的是,schemagen目标试图递归遍历foo / rest / execution / model目录,因此尝试为子目录中的类生成模式。
Is there a way to avoid that? 有办法避免这种情况吗?
You can use xjcSourceExcludeFilters
to filter the sources defined by source
ie to exclude packages, files etc. 您可以使用
xjcSourceExcludeFilters
过滤由source
定义的source
即排除包,文件等。
For example: 例如:
<configuration>
<sources>
<source>src/java/foo/rest/execution/model</source>
</sources>
<xjcSourceExcludeFilters>
<filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
<patterns>
<pattern>src/java/foo/rest/execution/model/builder/*.java</pattern>
</patterns>
</filter>
</xjcSourceExcludeFilters>
...
</configuration>
If the built-in filter support cannot meet your needs then you can provide your own implementation by replacing org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter
with your own implementation of AbstractFilter
. 如果内置过滤器支持无法满足您的需求,那么您可以通过使用自己的
AbstractFilter
实现替换org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter
提供自己的实现。
More details on using this here and more details on defining filters here . 使用此的更多细节在这里和定义过滤器的详细信息在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.