I am using jaxb2-maven-plugin for generating XSD from jaxb annotated classes.
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. Instead, I specified that I wish to include the whole src/java/foo/rest/execution/model
directory, using a single <source>
element.
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. 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.
Is there a way to avoid that?
You can use
xjcSourceExcludeFilters
to filter the sources defined bysource
i.e. to exclude packages, files etc.For example:
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 ofAbstractFilter
.More details on using this here and more details on defining filters here.