Question

i'm trying to generate classes that i can use from the validator xsd files found in:

C:\Program Files\Intuit\IDN\Common\tools\validator

i run:

xjc qbxmltypes.xsd qbxml.xsd qbxmlso.xsd qbxmlops.xsd

and the tool generates the 'generated' directory and class files as expected. however, these classes don't appear to work properly. i add the classes to my project, repackage them, and everything compiles just fine. when i create a new JAXBContext object thus:

JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);

in the normal way, this compiles just fine, but i get runtime errors (lots of them, repeating the same line) in System.err that read:

No XmlSchema annotation found for [packagenamehere]

i search the package path for usages of the XmlSchema, and none are found. JAXB apparently requires this at runtime.

am i using the wrong .xsd files? should i be adding the XmlSchema annotation to the ObjectFactory.java class? what am i doing wrong here? i think i'm just building the wrong classes with xjc. which .xsd files should i be compiling?

Was it helpful?

Solution

The XJC utility will generate classes into a package name based on the target namespace. If there isn't one the by default it will put them in a package called generated. You can supply a package name as a parameter.

xjc -p com.example.foo schema.xsd

I would recommend generating each of your schemas into a separate package. When creating a JAXBContext from classes generated from an XML schema I always recommend doing this on the package name. When there are multiple package names simply separate them with the . character.

JAXBContect jc = JAXBContext.newInstance("com.example.foo:com.example.bar");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top