users@jaxb.java.net

RE: ClassCastException in Eclipse -> Run

From: ray lukas <ray_lukas_at_comcast.net>
Date: Thu, 25 May 2006 22:12:44 -0400

I mine as well give you the Validator class also.. That is also new in JaxB
2.0 and a great feature.. Most people code this as an inline type thing but
I like to do it this way.

 

            private class Validator implements ValidationEventHandler{

                        public boolean handleEvent(ValidationEvent event){

                                    if (event.getSeverity() ==
ValidationEvent.WARNING){

 
Tracer.log("[Model::Validator::handleEvent(" + event.getMessage() + ") has
detected a warning");

                                    } else if (event.getSeverity() ==
ValidationEvent.ERROR){

 
Tracer.log("[Model::Validator::handleEvent(" + event.getMessage() + ") has
detected a ERROR");

                                    } else if (event.getSeverity() ==
ValidationEvent.FATAL_ERROR){

 
Tracer.log("[Model::Validator::handleEvent(" + event.getMessage() + ") has
detected a FATAL_ERROR");

                                    }

                                    return true;

                        }

            }

 

 The tracer.log is something I wrote up. Just pretend that it is log4J and
you will be all set..

  _____

From: Andrew Hughes [mailto:azza_at_lisasoft.com]
Sent: Thursday, May 25, 2006 9:46 PM
To: users_at_jaxb.dev.java.net
Subject: ClassCastException in Eclipse -> Run

 

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

--------------------------------------------------------------------- To
unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net For additional
commands, e-mail: users-help_at_jaxb.dev.java.net