my dog learned polymorphism*
The moose likes XML and Related Technologies and the fly likes Can the JAXB XJC compiler compile schemas that are in a jar file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Can the JAXB XJC compiler compile schemas that are in a jar file?" Watch "Can the JAXB XJC compiler compile schemas that are in a jar file?" New topic
Author

Can the JAXB XJC compiler compile schemas that are in a jar file?

Alex Hurtt
Ranch Hand

Joined: Oct 26, 2010
Posts: 98
I have been grappling with finding an answer to this for hours...on the surface it doesn't seem to work but maybe I'm doing it wrong. I have a jar file containing nothing but a directory structure full of various XSD files. I want to be able to use either the XJC.exe (with sun/oracle java 6) or the XJC Ant task to target and compile certain schemas out of this jar file without having to extract them. According to the documentation you are supposed to be able to supply an XSD file name or a URL or a directory containing one or more schemas or a jar file as the input to XJC. So far I can only get it to work when I extract the jar file contents and specify a specific XSD file or directory. That is not desirable. I have tried something like this (assuming the jar file is name 'myjarfile.jar'):

xjc myjarfile.jar

I get an error saying something like "no grammar was specified"

I try specifying as a URL...something like this:

xjc jar:file:/myjarfile.jar!/path/to/schemafile/targetschema.xsd

This just doesn't work as it appears not to be able to locate the schema this way. I have verified the path and jar file directory structures and I'm almost sure I didn't make a mistake in the path reference. Am I trying to do something that just wasn't meant to be here or am I just screwing it up somehow?

EDIT: I notice also it says that if you specify a jar file that /META-INF/sun-jaxb.episode will be compiled...however the jar file contains no such file and I cannot put one there since I am not allowed to modify the jar file contents. So am I out of luck...must this file be present to give a jar file of schemas to XJC or is it optional?
Alex Hurtt
Ranch Hand

Joined: Oct 26, 2010
Posts: 98
Tried this again on a different computer and the method using:

xjc jar:file:/path/to/jarfile.jar!/path/to/targetschema.xsd

actually does work so...must be a configuration, bug, or version issue on the other machine.
 
 
subject: Can the JAXB XJC compiler compile schemas that are in a jar file?