I have a large number of Generated Classes in my project that are generated using an xjc
ant task. By default, the generation process creates an ObjectFactory.java
class. I was wondering if there was a way to suppress the creation of ObjectFactory and instead generate a jaxb.index
file.
My understanding is that jaxb.index is more optimal than ObjectFactory for object serialization & deserialization.
I'm working with Ant 1.10.3 & JAXB 2.3.0
Thanks.
First a warning: make sure you know what you do. ObjectFactory
has a few features (like supporting substitution groups) which jaxb.index
does not have. So suppressing ObjectFactory
may lead to not being able to parse valid XML.
Now, assuming you know what you do, how to do it.
JAXB2 Basics includes a "JAXB Index" plugin which generates jaxb.index
. Usage in Ant would be something like:
<xjc destdir="${basedir}/target/generated-sources/xjc" extension="true">
<arg line="
-Xjaxbindex"/>
<binding dir="${basedir}/src/main/resources">
<include name="**/*.xjb"/>
</binding>
<schema dir="${basedir}/src/main/resources">
<include name="**/*.xsd"/>
</schema>
<!-- Plugins -->
<classpath>
<fileset dir="${basedir}/lib">
<!-- JAXB2 Basics library -->
<include name="jaxb2-basics-plugins-*.jar"/>
</fileset>
</classpath>
</xjc>
To suppress ObjectFactory
, simply delete the generated file.
Disclaimer: I am the author of JAXB2-Basics. I am not sure wether it works with JAXB 2.3.0.