The instructions to generate schema through running "schenagen" as suggested in Java API documentation worked with JDK7, but not with JDK8.
Here is the documentation page: http://download.java.net/jdk8/docs/technotes/guides/xml/jaxb/index.html
Here is the line from this page with links to the instructions:
" Running the schema generator (schemagen): [command-line instructions, using the SchemaGen Ant task] "
Schema generator does not work because some classes have been removed from JDK8: "java.lang.ClassNotFoundException: com.sun.mirror.apt.AnnotationProcessorFactory"
There is another solution suggested here: Generating XSD schemas from JAXB types in Maven?
This solution also works with JDK7 but not with JDK8; it will end up with a similar error:
"Class not foundcom/sun/tools/apt/Main.class"
The root cause is probably the same: the annotation processing tools are removed from JDK8. This change was planned in JEP 117 long time ago: http://openjdk.java.net/jeps/117
How can I generate an XML schema file from (JAXB) annotated Java classes now, using JDK8?
After the Java artifacts for your application are generated, you can generate fully annotated Java classes from an XML schema file by using the JAXB schema compiler, xjc command-line tool.
In the main menu, go to Tools | XML Actions | Generate XML Schema From Java Using JAXB. In the dialog that opens, specify the method parameter and return types to be reflected in the generated Schema: To have all the class methods involved, clear the Include parameter and return type of the following methods checkbox.
Generate a Java class from an XML Schema using JAXB In the active editor tab, open the desired Schema . xsd file or an XML document, which contains the desired Schema. In the main menu, go to Tools | XML Actions | Generate Java Code From XML Schema Using JAXB.
Just build the maven project using mvn clean install and you will see java classes generated in target/generated-sources/jaxb directory.
This was a bug in the "jaxb2-maven-plugin". You must use the version 1.6 or later of the plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includes>
<include>com/projectname/model/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/schemas</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With