Grails script to generate JAXB classes

Posted by Unknown Sunday, December 9, 2012 0 comments
20121127 Tuesday November 27, 2012

Grails script to generate JAXB classes

I think Groovy's MarkupBuilder is great and I use it often. Sometimes though, I need to generate a complex XML document that conforms to an XSD. MarkupBuilder often leads to markup and business logic being mixed together much like HTML and Java code gets mixed in complex JSP pages. In cases like this, I like to use JAXB instead. I can generate classes from the XSD, load up an object model and let JAXB generate the markup.


It's fairly easy to create a script to handle generating the JAXB classes for you. JAXB comes with a handy Ant task that takes your XSD and generates classes. The trick is passing the build classpath to the task. There is a "grailsSettings" variable available in scripts that contains BuildSettings. We can get the list of build dependencies files from this class to generate the classpath. Here is a simple example that takes the Microsoft books.xsd in the etc/schema directory and generates the code to the src/java directory:


UPDATE: Sometimes having the JAXB jars on your path can cause problems with your application. In those cases, you call the generation class directly:

(2012-11-27 22:12:29.0) Permalink

View the original article here

THANK YOU FOR YOUR VISIT
Title: Grails script to generate JAXB classes
Posted By Unknown
Blog Rating 5 dari 5
Hopefully this article useful to you. If you wish to quote, either part or all of the contents of this article please include a "dofollow links" to http://izone2.blogspot.com/2012/12/grails-script-to-generate-jaxb-classes.html. Thank you for reading our articles and continue to follow this blog article.

0 comments:

Post a Comment

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of Info Zone.