groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From obesga <>
Subject Can not use JAXB into a groovy script
Date Fri, 22 Jul 2016 17:17:30 GMT
Hi, fellow groovylanders

I have  a problem with groovy scripts, JAXB marshaller and I think it is the classloader of
groovy scripts
But no problem executing this code into a groovy class (with a main launcher)  

The code is here
try {

    StringReader stringReader = new StringReader(dataa);
    JAXBContext jaxbContextRespuesta = JAXBContext.newInstance(MensajeWS.class)
    Unmarshaller unmarshallerRespuesta = jaxbContextRespuesta.createUnmarshaller();
    MensajeWS mensajeWSRespuesta = (MensajeWS) unmarshallerRespuesta.unmarshal(stringReader)

    println mensajeWSRespuesta;
} catch(Exception e) {
    println e

The exception is this
	at javax.xml.bind.ContextFinder.handleClassCastException(
	at javax.xml.bind.ContextFinder.newInstance(
	at javax.xml.bind.ContextFinder.newInstance(
	at javax.xml.bind.ContextFinder.find(
	at javax.xml.bind.JAXBContext.newInstance(
	at javax.xml.bind.JAXBContext.newInstance(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.codehaus.groovy.reflection.CachedMethod.invoke(
	at groovy.lang.MetaMethod.doMethodInvoke(
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at esto.groovy:65)
	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(

I’m using IntelliJIdea to launch it
- when launched as groovy mean class - java standard it goes ok
- when launched as groovy script, error is thrown

I think it’s a class loader problem, but after searching on the web (like stack overflow)
I’m out of ideas

Anyone has a similar problem ?


Oscar Besga

View raw message