The JPMML-Model library provides a Java class model for the Predictive Model Markup Language (PMML) standard. The core set of JPMML-Model classes have been generated based on the PMML XML Schema Definition (XSD) file using the XJC binding compiler technology. As such, they are heavily dependent on the Java XML Binding (JAXB) runtime.
The JAXB runtime was more or less an integral part of Java SE versions 1.6 thorugh 1.8. However, with the advent of Java SE 9 module system, the JAXB runtime was isolated to a
java.xml.bind module, and excluded from the core (ie. active by default) module set.
If a Java SE 9 (or newer) application wants to use JAXB runtime functionality, then it can do one of the following:
- Activate the
java.xml.bindmodule using the
--add-modules java.xml.bindcommand-line option.
- Leave the
java.xml.bindmodule inactive, and add a functionally equivalent set of Java libraries/classes straight to the application classpath.
The second option is seen as cleaner and safer. Meddling with Java/JVM startup options just to please one application is bad style. Furthermore, there remains uncertainty about the JAXB runtime version, and if all transitive dependencies (internal APIs for power users) are available and sufficiently up to date.
The JPMML-Model library declares a compile-time dependency ("provided" Apache Maven scope) on GlassFish Metro and EclipseLink MOXy runtimes.
If a Java application declares a run-time dependency ("compile" and "runtime" Apache Maven scopes) only on the JPMML-Model library, then it is limited to the first deployment scenario. However, if the Java application declares a run-time dependency on the JPMML-Model library plus one or more JAXB runtimes, then it can follow either development scenario.
This blog post details the proper configuration of GlassFish Metro runtime. The analysis is based on a
jaxb_demo demo application, which deals with marshalling and unmarshalling an empty PMML class model object.
The project is built and deployed throughout this exercise using the following sequence of commands:
Java SE 1.8(.0_162)
The project can be built and deployed without any formal GlassFish Metro dependency.
The default JAXB runtime does not collect and propagate SAX Locator information, which means that the
org.dmg.pmml.PMMLObject#locator field is left uninitialized. If the Java application (eg. the unmarshalling demo application) is interested in this information, then it needs to declare the
org.glassfish.jaxb:jaxb-runtime library as a run-time dependency:
Java SE 9(.0.4) and 10(.0.2)
Apache Maven activates all Java EE modules (including the
java.xml.bind module) during compilation, so the project can again be built without any formal GlassFish Metro dependency.
However, now and in the future, the
org.glassfish.jaxb:jaxb-runtime library has become a required run-time dependency. If missing, then any attempt to make use of some JAXB class or interface will result in a
org.glassfish.jaxb:jaxb-runtime library currently depends on six other Java libraries:
org.glassfish.jaxb:jaxb-runtime– Glassfish Metro runtime. Provides
com.sun.istack:istack-commons-runtime– Istack Common Utility Code Runtime. Provides
com.sun.xml.fastinfoset:FastInfoset– Fast Infoset Standard for Binary XML. Provides
org.jvnet.fastinfoset.*classes. Required when working with binary XML documents; not required when working with text-based XML documents.
jakarta.activation:jakarta.activation-api– JavaBeans Activation Framework API. Provides
jakarta.xml.bind:jakarta.xml.bind-api– Java XML Binding (JAXB) API. Provides
org.glassfish.jaxb:txw2– TXW2 Runtime. Provides
com.sun.xml.txw2.*classes. Not required.
org.jvnet.staxex:stax-ex– Extensions for StAX API. Provides
org.jvnet.staxex.*classes. Not required.
For example, declaring a minimal GlassFish Metro dependency:
These three exclusions reduce the size of the
jaxb_demo uber-JAR file a bit over 400 kB.
Java SE 11(.0.2)
Java SE 11 removed all Java EE modules, including the
java.xml.bind module. Since Apache Maven is unable to provide Java XML Binding classes on its own, the project becomes non-buildable:
After declaring the minimal GlassFish Metro dependency, the project can be built and deployed as before.
- Java application: "jaxb_demo.zip"