XJC Utils
The Apache CXF XJC-Utils subproject provides a collection of XJC (JAXB XML-to-Java compiler) plugins and utilities for generating better or more usable code. The extensions augment CXF's code-generation pipeline when compiling XML Schemas and WSDL files into Java.
Modules
Module | Artifact | Option | Description |
|---|
cxf-xjc-plugin
| org.apache.cxf:cxf-xjc-plugin
| Maven goals xsdtojava / xsdtojava-tests | Maven plugin that runs XJC on standalone XML Schemas, optionally with the extensions below. |
cxf-xjc-dv
| org.apache.cxf.xjcplugins:cxf-xjc-dv
| -Xdv
| Initializes fields mapped from elements with their schema default values. |
cxf-xjc-ts
| org.apache.cxf.xjcplugins:cxf-xjc-ts
| -Xts
| Adds a toString() method to generated classes that prints the value of every field (using cxf-xjc-runtime at runtime). This includes any sensitive data, such as passwords or tokens, so take care when logging generated objects. |
cxf-xjc-boolean
| org.apache.cxf.xjcplugins:cxf-xjc-boolean
| -Xbg / -Xbgi
| -Xbg generates getXXX() instead of isXXX() for Boolean properties; -Xbgi generates both.
|
cxf-xjc-javadoc
| org.apache.cxf.xjcplugins:cxf-xjc-javadoc
| -Xjavadoc
| Generates Javadoc from xsd:documentation. |
cxf-xjc-pl
| org.apache.cxf.xjcplugins:cxf-xjc-pl
| -Xproperty-listener
| Adds a PropertyChangeListener to all set methods. |
cxf-xjc-wsdlextension
| org.apache.cxf.xjcplugins:cxf-xjc-wsdlextension
| -Xwsdlextension
| Adds WSDL extension methods so generated beans can be used as WSDL4J extensors. |
cxf-xjc-bug671
| org.apache.cxf.xjcplugins:cxf-xjc-bug671
| -Xbug671
| Maps package names that contain Java keywords. (Originally a workaround for the legacy JAXB issue 671.) |
cxf-xjc-bug986
| org.apache.cxf.xjcplugins:cxf-xjc-bug986
| -Xbug986
| Removes @XmlSchemaType(anySimpleType) from fields that should not have it. |
cxf-xjc-runtime
| org.apache.cxf.xjc-utils:cxf-xjc-runtime
| (support library) | Runtime support classes used by code generated with some of the plugins (e.g. -Xts). |
Note that the artifacts use different groupIds: the Maven plugin is org.apache.cxf:cxf-xjc-plugin, while the XJC extensions are under org.apache.cxf.xjcplugins. When searching Maven Central, search by artifactId (e.g. cxf-xjc-dv) rather than by a single groupId.
With the exception of cxf-xjc-runtime, the XJC plugins are code-generation utilities only and are not used at runtime.
Versioning
CXF XJC Utils is released independently of Apache CXF, and its version numbers do not track CXF releases. Use the latest XJC Utils release from the same major line as your CXF version (4.x for CXF 4.x, which uses Jakarta XML Binding; 3.x for CXF 3.x, which uses javax.xml.bind). Available versions are listed on Maven Central.
Requirements
- Java 17+
- Maven 3.6.3+
- Apache CXF 4.x (for the matching release line)
Usage
With cxf-codegen-plugin (WSDL to Java), add the desired extension as a dependency of the cxf-codegen-plugin Maven plugin and activate it with an extraarg of the form -xjc-X<id>:
<configuration>
<defaultOptions>
<extraargs>
<extraarg>-xjc-Xdv</extraarg>
</extraargs>
</defaultOptions>
</configuration>
With cxf-xjc-plugin (XML Schema to Java), list the extension under <extensions> and pass its flag under <extensionArgs>:
<extensionArgs>
<arg>-Xdv</arg>
</extensionArgs>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:${cxf-xjc-utils.version}</extension>
</extensions>
Source
The source code is at github.com/apache/cxf-xjc-utils:
git clone https://github.com/apache/cxf-xjc-utils.git
Building follows the build instructions for the main CXF project.