XML : how to generate only required classes from XSDs via maven-jaxb

I have two XSDs where one includes the other, lets call them A and B.

B has a lot of xs:complexType definitions and is included by A, however A is interested in using only some of those.

What happens right now is that classes for all types defined in B are generated. What i would like to achieve is to generate classes only for types which are directly referenced by A.

I have tried to modify XSD A to import B instead of include but it didn't work out for maven-jaxb plugin.

XSD A import of B:

  <xs:import schemaLocation="B.xsd" />    

Plugin setup for generating sources:

          <plugin>              <groupId>org.jvnet.jaxb2.maven2</groupId>              <artifactId>maven-jaxb2-plugin</artifactId>              <executions>                  <execution>                      <id>generate-wsdl</id>                      <goals>                          <goal>generate</goal>                      </goals>                      <configuration>                          <schemaDirectory>src/main/resources</schemaDirectory>                          <schemaIncludes>                              <include>newXSD/*.xsd</include>                          </schemaIncludes>                          <strict>true</strict>                          <extension>true</extension>                          <args>                              <arg>-XJsr303Annotations</arg>                              <arg>-Xannotate</arg>                          </args>                          <plugins>                              <plugin>                                  <groupId>org.jvnet.jaxb2_commons</groupId>                                  <artifactId>jaxb2-basics-annotate</artifactId>                                  <version>0.6.3</version>                              </plugin>                              <plugin>                                  <groupId>com.github.krasa</groupId>                                  <artifactId>krasa-jaxb-tools</artifactId>                                  <version>1.1</version>                              </plugin>                          </plugins>                      </configuration>                  </execution>              </executions>          </plugin>    

I understand there is a way to achieve what i ask with xjc from command line, but then the plugins for annotating classes for validation do not trigger.

What i need is a way to generate only required classes while keeping runtime annotations such as @NotNull generated by plugins bellow. Can somebody please help with this ?

No comments:

Post a Comment