Generate JAXB Java classes from XSD with maven-jaxb2-plugin AND Spring OXM JAXB Example

  Рет қаралды 32,651

Philip Starritt

8 жыл бұрын

Generating Java JAXB classes from an XSD schema is a common task. In this tutorial I show you how to use the maven-jaxb2-plugin to generate the JAXB java classes. (From group org.jvnet.jaxb2.maven2).
By the way - have you tried MOXy? I actually find it more maintainable than handing JAXB objects; but thats another video topic!.
I additionally show you how to use Spring Framework OXM Jaxb2Marshaller to marshal JAXB java objects into XML and unmarshal XML into JAXB java objects.
00:00 - 01:23 Tutorial Introduction from a beach in Andalusia; Spain. During my morning walk.
01:23 - 01:46 Create Spring Starter Project
01:46 - 02:40 Created XML XSD Schema
02:40 - 03:50 Added maven-jaxb2-plugin to the applications POM
03:50 - 04:40 Generated the JAXB Java Objects representing the schema
04:40 - 04:52 Added Spring Framework OXM dependency to the POM
04:52 - 08:55 Created Spring Jaxb2Marshaller with context path, schema resource validation and pretty print property.
08:55 - 10:33 Created JAXB Java Objects to perform marshalling on
10:33 - 12:30 Marshalled JAXB Java Object into XML with Jaxb2Marshaller StreamResult and StringWriter. Could also use StringResult.
12:30 - 13:00 Fixed the exception thrown by adding the missing context path and schema properties.
13:00 - 14:45 Unmarshalled XML into JAXB java objects using Jaxb2Marshaller StreamSource and StringReader.
14:45 - 15:50 Maven & Spring JAXB Integration example summary
I hope you learned something new and enjoyed the video; subscribe for more regular tech videos!
Enjoy! :)
Philip
JAXB2 Maven Plugin: github.com/highsource/maven-jaxb2-plugin
JAXB2 Maven Plugin Configuration Cheat Sheet: github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet
Alexey Valikov Highsource: github.com/highsource
Spring Framework Marshalling XML using O/X Mappers: docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html
Jaxb2Marshaller: docs.spring.io/spring/docs/current/javadoc-api/org/springframework/oxm/jaxb/Jaxb2Marshaller.html
Spring Initializr: start.spring.io/
MOXy EclipseLink for the interested: wiki.eclipse.org/EclipseLink/Examples/MOXy

Пікірлер: 14
@MrTalJacob
@MrTalJacob 3 жыл бұрын
Amazingly explained. Couldn't do it without you!
@medacjaime8886
@medacjaime8886 Жыл бұрын
this video is useless for me but i like that you explain the video in a beach from andalusia (where I live)
@warrenbates934
@warrenbates934 3 жыл бұрын
Excellent thanks.
@avijitsharma5050
@avijitsharma5050 5 жыл бұрын
Neatly explained !! Just wanted to add : if you can summarize at the end with help of PPT, that wud be great !!
@TowerJimmy
@TowerJimmy 6 жыл бұрын
useful
@abhishekprasad1814
@abhishekprasad1814 6 жыл бұрын
can u tell me how to do same in gradle project
@TheDukeGreat
@TheDukeGreat 5 жыл бұрын
Doesn't seem to generate classes with this method, any other ideas?
@save2strokes593
@save2strokes593 3 жыл бұрын
i am not getting targeted resource package ,while updating the maven project ,i am getting the error like this(An internal error occurred during: "Building". com.sun.tools.xjc.Plugin: com.sun.tools.xjc.addon.accessors.PluginImpl Unable to get public no-arg constructor).plz any one can help from this
@usbcloud5340
@usbcloud5340 Жыл бұрын
Nice intro, great beach. 👍
@borjovsky3164
@borjovsky3164 3 жыл бұрын
How to do it to all XSD in a folder?
@sugandharajpal
@sugandharajpal 6 жыл бұрын
There isn’t @XMLRootElement while JaXB classes got generated
@StrongbowJava
@StrongbowJava 3 жыл бұрын
Doesn't work anymore. Here some fixes. Add a dependency org.glassfish.jaxb jaxb-runtime Change code on JaxbConfig.java here: from in method signature: @Value("${schema.location}") final Resource schemaResource to in method signature: @Value("${schema.location}") final String schemaResource inside the method: Resource schema = new ClassPathResource(schemaResource); marshaller.setSchema(schema); See Stackoverflow: stackoverflow.com/questions/43429514/resource-servletcontext-resource-does-not-exist and Github jaxb- issues: github.com/eclipse-ee4j/jaxb-ri/issues/1235#issuecomment-474306717
@rabinarayansabat9166
@rabinarayansabat9166 Жыл бұрын
Getting JAXBException: Com.philipstarritt.orders does not contain ObjectFactory.class or jab.index however I could see ObjectFactory.class is present
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 15 МЛН
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 30 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 15 МЛН