Does JAXB support modular code generation?
Most of my background is with JibX for XML marshalling, but for legacy reasons our firm is using JAXB.
One feature that was available for JIBX was modular code generation. Say I have a main schema but I have several different envelopes for that schema. With JibX I could create a jar file out of the JibX'ed core schema, and then in separate projects I could JibX my envelope schemas and simply point to the shared jar instead of having to duplicate the code generation of the core schemas for each envelope.
I don't yet see a way for JAXB to handle this - has anyone been successful doing something like this?
Thanks in advance, Roy
Using a JAXB 2.1 implementation (Metro, EclipseLink MOXy, Apache JaxMe, etc), you can specify that schema types correspond to existing classes in order to prevent them from being generated.
For example:
root.xsd
imported.xsd
Problem Statement
If you use the XJC tool to generate java classes from the XML schema:
You the following is generated:
imported-bindings.xml
You can use a JAXB bindings file to specify that types from imported.xsd point to existing classes:
Running the XJC
Now if we run XJC with out bindings file:
None of the files specified in the bindings file will be generated:
Alternative Approach
The code generated from the imported schema directly (xjc imported.xsd) and indirectly (xjc root.xsd) is the same. You can simply drop the code generated indirectly and point at the project containing the code that was generated directly.
For the JAXB RI, that's handled with "episode" files (these are really just customization files). Process the core schema first, making sure to have xjc use the
-episode <file>
arg. Package the results of that processing into a JAR file with the episode file inMETA-INF/sun-jaxb.episode
. Then, pass that JAR file as an arg to xjc when processing the other schemas.