Skip to content
Stefan Bodewig edited this page Jan 25, 2022 · 5 revisions

JAXB

The Java Architecture for XML Binding (now Jakarta XML Binding) has a somewhat winded history. From Java 6 to 10 it has been part of the standard class library (it has been deprecated as part of the Standard Edition since Java 9). It has been split out as a specification under the JavaEE umbrella and is now part of Jakarta EE.

The API of JAXB used to live in the javax.xml.bind package, starting with Jakarta XML Binding 3.x the package has changed to jakarta.xml.bind.

XMLUnit 2.x uses JAXB to provide a Source either explicitly via Input.fromJaxb or implicitly as last fallback in Input.from.

xmlunit-core supports JAXB using the javax.xml.bind package out of the box. Support for the jakarta.xml.bind has been added with XMLUnit for Java 2.9.0 in the form of an extra module you need to add.

How can I use JAXB

I am using Java Standard Edition 7 or 8 and want to use javax.xml.bind

Your project must not depend on org.xmlunit:xmlunit-jakarta-jaxb-impl at all.

All required JAXB dependencies are already provided by the Java class library.

I am using Java Standard Edition > 8 and want to use javax.xml.bind

Your project must not depend on org.xmlunit:xmlunit-jakarta-jaxb-impl at all.

In addition to xmlunit-core your project must depend on jakarta.xml.bind:jakarta.xml.bind in a 2.x version (but not higher!) as well as an implementation of said API - for example org.glassfish.jaxb:jaxb-runtime with a matching version.

I want to use jakarta.xml.bind

Note, Jakarta XML binding requires Java Standard Edition 8 at a minimum.

Your project needs to depend on org.xmlunit:xmlunit-jakarta-jaxb-impl in addition to xmlunit-core. In addition it must depend on jakarta.xml.bind:jakarta.xml.bind of a 3.x version (or higher) as well as an implementation of said API - for example org.glassfish.jaxb:jaxb-runtime with a matching version.

Technical Details

Starting with XMLUnit 2.9.0 the JaxbBuilder class returned by Input.fromJaxb has become abstract and the concrete implementation is provided by a JaxbBuilderFactory that is loaded using Java's ServiceLoader mechanism. In theory this allows other modules to provide implementations of JaxbBuilderFactory of their own, but such usage is not explicitly supported by XMLUnit and may stop working with future releases.

Maven Enforcer Complains about xmlunit-core targetting Java 7 but Having a Java 8 Dependency

If your project uses the Maven enforcer plugin and builds with Java 9 or above it may complain about xmlunit-core having a dependency on a library with Java 8 as minimal class version (jakarta.xml.bind:jakarta.xml.bind-api:2.x) even though the project itself targets Java 7. This is true, but we believe this to be a non-issue as the dependency is not required when running XMLUnit on Java 7 at all and the API xmlunit-core has been compiled against is compatible with javax.xml.bind that is part of the Java class library (it has been removed with Java 11).

If your project doesn't use JAXB at all, the easiest way to remove the warning is to exclude the JAXB dependencies for xmlunit-core. For more details see xmlunit/#248.