The following example shows a simple maven plugin configuration to generate Java beans from a XSD. I use the “maven-jaxb22-plugin” because it allows a simple integration of plugins to adjust the Bean generation. Leave the following arguments if you don’t need the feature:
- Xsetters - Generates setters to beans
- XtoString - Generates common to string method to beans
- Xequals - Generates a equals method to beans
- XhashCode - Generates a hashcode method to beans
- Xfluent-api - Generates a fluent API to beans
1: <plugin>
2: <groupId>org.jvnet.jaxb2.maven2</groupId>
3: <artifactId>maven-jaxb22-plugin</artifactId>
4: <executions>
5: <execution>
6: <id>Generating Asset Admin Api Beans</id>
7: <goals>
8: <goal>generate</goal>
9: </goals>
10: <configuration>
11: <encoding>UTF-8</encoding>
12: <forceRegenerate>true</forceRegenerate>
13: <schemaDirectory>${basedir}/src/main/resources/xsd/</schemaDirectory>
14: <generatePackage>de.lehavre.demo</generatePackage>
15: <schemaIncludes>
16: <include>model1.xsd</include>
17: <include>model2.xsd</include>
18: </schemaIncludes>
19: <extension>true</extension>
20: <args>
21: <arg>-Xsetters</arg>
22: <arg>-XtoString</arg>
23: <arg>-Xequals</arg>
24: <arg>-XhashCode</arg>
25: <arg>-Xfluent-api</arg>
26: </args>
27: <plugins>
28: <plugin>
29: <groupId>org.jvnet.jaxb2_commons</groupId>
30: <artifactId>jaxb2-basics</artifactId>
31: </plugin>
32: <plugin>
33: <groupId>net.java.dev.jaxb2-commons</groupId>
34: <artifactId>jaxb-fluent-api</artifactId>
35: <version>2.1.8</version>
36: </plugin>
37: </plugins>
38: </configuration>
39: </execution>
40: </executions>
41: </plugin>