This is a maven plugin/mojo to generate JSON schema files from JAXB annotated classes. JSON schemas are generated using jackson-module-jsonSchema
- JDK 8
- Maven 3+
- JAXB 2.2+
- Jackson 2.8.8
-
Create a maven project that contains JAXB annotated classes
-
Add the maven mojo as a plugin.
<plugin> <groupId>org.anair.maven</groupId> <artifactId>jsonschema-gen-mojo</artifactId> <version>0.0.1</version> <configuration> <jaxbDirectory>${basedir}/target/generated/jaxb</jaxbDirectory> <jsonschemaDirectory>json-schema</jsonschemaDirectory> <includes> <include>/com/foo/**.java</include> </includes> <excludes> <exclude>/com/foo/Bar.java</exclude> </excludes> </configuration> <executions> <execution> <goals> <goal>jaxb-jsonschema-gen</goal> </goals> </execution> </executions> </plugin>
- The default phase is generate-resources
- Specify the JAXB source directory
- Specify target JSON schema directory. Defaulted to src/main/resources/json-schema
- Specify packages/classes to be included or excluded
- Run
mvn generate-resources
- JSON schema files will be in "jsonschemaDirectory"