I used JAXB to create classes from an XML schema file.
Here is a snippet of code:
JAXBContext jc = JAXBContext.newInstance( "surfTest" );
ObjectFactory objFactory = new ObjectFactory();
UserEnteredProfile uep=
objFactory.createUserEnteredProfile();
uep.setTime("12:00 p.m.");
uep.setProfileName("JAXB_TEST");
uep.setEditFlag("N") ;
uep.setDate("08/08/2003");
uep.setSightLine(new BigDecimal(120.0));
ClassType navoClass = createClassification(objFactory);
// create a Marshaller and marshal to a file
Marshaller m = jc.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE );
Whenever the code to create the Marshaller is executed I get the
following error.
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for
J2EE].naming.ContextClassLoader.defineClass(ContextClassLoader.java:1102)
at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for
J2EE].naming.ContextClassLoader.findClass(ContextClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for
J2EE].naming.ContextClassLoader.loadClass(ContextClassLoader.java:135)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for
J2EE].naming.ContextClassLoader.defineClass(ContextClassLoader.java:1102)
at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for
J2EE].naming.ContextClassLoader.findClass(ContextClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for
J2EE].naming.ContextClassLoader.loadClass(ContextClassLoader.java:135)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at surfTest.impl.runtime.DefaultJAXBContextImpl.createMarshaller(DefaultJAXBContextImpl.java:104)
Any ideas/suggestions?
Thanks,
MJ
>I used JAXB to create classes from an XML schema file.
I burst out laughing when I ready about JAXB. What is the advantage of
writing that long-winded, complicated, screwy XML to generate trivial
Java class files?
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
> On 8 Aug 2003 09:47:53 -0700, mjohn...@yahoo.com (Michael) wrote or
> quoted :
>
>>I used JAXB to create classes from an XML schema file.
>
> I burst out laughing when I ready about JAXB. What is the advantage of
> writing that long-winded, complicated, screwy XML to generate trivial
> Java class files?
>
I think you're missing the point of JAXB.
It's not about creating classes, it's about marshalling instances of classes
to/from XML, in a transparent manner without writing (any) boilerplate
code. Just defining an xml schema is much easier and less work than
creating/parsing the xml from the instances yourself.
--
mvg,
Christophe Vanfleteren
>I think you're missing the point of JAXB.
>It's not about creating classes, it's about marshalling instances of classes
>to/from XML, in a transparent manner without writing (any) boilerplate
>code. Just defining an xml schema is much easier and less work than
>creating/parsing the xml from the instances yourself.
but surely feeding the class files to create the marshal/unmarshall
code would be easier than feeding the XML.
> On Fri, 08 Aug 2003 18:12:10 GMT, Christophe Vanfleteren
> <c.v4nf...@p4nd0r4.b3> wrote or quoted :
>
>>I think you're missing the point of JAXB.
>>It's not about creating classes, it's about marshalling instances of
>>classes to/from XML, in a transparent manner without writing (any)
>>boilerplate code. Just defining an xml schema is much easier and less work
>>than creating/parsing the xml from the instances yourself.
>
> but surely feeding the class files to create the marshal/unmarshall
> code would be easier than feeding the XML.
>
It sure is, and that is what frameworks as Castor can do: there is no need
to write a schema in most cases, unless you want more control of the
marshalling process (eg. what should be an element / attribute, ...).
--
mvg,
Christophe Vanfleteren
If you have nothing helpful, why in the hell did you bother posting?
Wow, Michael. You're really adept at ensuring that you'll never get
help from one of the most helpful people in this group. If someone
knows the answer, they'll probably post about it. It doesn't hurt you
for Roedy to post his opinions about the API.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
You are right, my frustration level with trying to solve this problem
got the best of me.
Unless, of course, you've already got XML schemas from an external
source, like a specification that you're trying to implement. Then it's
no work at all to use the existing XML schema and get a Java class to
access it, but it's a considerable job to write your own marshalling and
unmarshalling code for the existing format specification.
>
>If you have nothing helpful, why in the hell did you bother posting?
The "helpfulness" was the suggestion that JAXB is an idiotic tool and
should be abandoned.