Java and XML story 1: generate a Java class through XSD
JAXB makes the tedious mechanical coding between Java and XML a thing of the past, now you can simply generate the corresponding Java file through the XSD file, I generally use the maven-jaxb2-plugin to generate xsd to the java file.
POM Configuration
Specify the xsd file path, specify the binding file path, and specify the java file path to be generated.
org.jvnet.jaxb2.maven2
maven-jaxb2-plugin
0.9.0
schema1-generate
generate
src/main/resources/dir1
1.xsd
true
${project.build.directory}/generated-sources/xjc1
${project.build.directory}/generated-sources/xjc1/META-INF/1.episode
src/main/resources/dir1
1.xjb
Binding. xjb Configuration
Implement type Matching and package matching. If the type matching is complex, you may need to implement your own conversion class.
Note1:The new version of plugin can not only generate java class, but also help generate the most important methods of the object: toString, equals, hashCode, clone, as long as you configure the plugin in configuration.
true
-XtoString -Xequals -XhashCode -Xcopyable
org.jvnet.jaxb2_commons
jaxb2-basics
Note2:I have encountered two xsd files in the same project with the same node type and different content. Although different packages are specified for generate source, an error is returned, the final solution is to use two executions to parse different xsd files, but I didn't encounter this problem when using the cxf plug-in. I can generate all the desired Java classes in one execution.