// in a script run from command line this is ok:
JAXBContext = Class.forName( 'javax.xml.bind.JAXBContext' )
Marshaller = Class.forName( 'javax.xml.bind.Marshaller' )
// if the groovy script / class is loaded from a java app, then the above may fail as it uses the same classloader to load the class as the containing script / class was loaded by. In that case, this should work:
JAXBContext = Class.forName( 'javax.xml.bind.JAXBContext', true, loader )
Marshaller = Class.forName( 'javax.xml.bind.Marshaller', true, loader )

4. To instantiate the classes, use the newInstance method:

def jaxbContext = JAXBContext.newInstance( MyDataClass )

Note that newInstance is on steroids when called from groovy. In addition to being able to call the parameterless constructor (as w/ Java's Class.newInstance()), you can give any parameters to invoke any constructor, e.g.