JAXB Context Exception when marshalling
802451Oct 1 2010 — edited Oct 4 2010Hi,
I am doing a proof-of-concept with JAXB. I have successfully compiled the Java objects with my schema. The 365 Java classes are in the correct package specified to the jaxb schema compiler along with the ObjectFactory class. I am using ant to run this. I am using Java 6 and am pointing to the com.sun.xml.bind.v2.runtime.JAXBContextImpl for my runtime.
I get the following exception:
runOtaSchemaProto:
[java] javax.xml.bind.JAXBException: class com.sandbox.mypkg.MyTestSchema nor any of its super class is known to this context.
[java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:594)
[java] at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:482)
[java] at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
[java] at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
[java] at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
The ant I used to compile my schema and the java I use to marshal to xml are below. Any help would be appreciated. (Note also that I get the exception whether I have populated the child/nested attributes or just instantiate my root element object and do not set any of its attributes.)
THE ANT:
<target name="bindMySchema">
<exec executable="${myEnv.JAVA_HOME}/bin/xjc.exe">
<arg value="-d"/>
<arg value="${src.dir}"/>
<arg value="-p"/>
<arg value="${pms.htng.pkg.name}"/>
<arg value="${my.schema.gen.dir}/MyTestSchema.xsd"/>
</exec>
</target>
private void marshallXml(MyTestSchema schemaObj) {
try {
JAXBContext jc = JAXBContext.newInstance("com.sandbox.gen");
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
m.marshal(schemaObj, System.out);
} catch (JAXBException jaxbe) {
jaxbe.printStackTrace();
}
}