users@jaxb.java.net

ClassCastException in Eclipse -> Run

From: Andrew Hughes <azza_at_lisasoft.com>
Date: Fri, 26 May 2006 11:15:56 +0930
Hey All,

I've read the FAQ and seen the problems with Class Loaders... I'm invoking my class from inside "Eclipse -> Run -> Run As: Java Application"

My code is:
JAXBContext jc = JAXBContext.newInstance("com.mypackage",this.getClass().getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
MyClass myXml = (MyClass) u.unmarshal(myXmlFile);
However I get a typical ClassCast Exception:
java.lang.ClassCastException: javax.xml.bind.JAXBElement
    at com.mypackage.TestService.run(TestService.java:24)
    at com.mypackage.MyClass.main(MyClass.java:18)

My symptoms are exactly the same as :  https://jaxb.dev.java.net/faq/index.html#classloader

I would prefer to try and solve this problem rather than having to deploy my code to tomcat all the time, or running from command line (if possible).


Thanks in advance.

AH