The Apache Software Foundation > Apache XMLBeans
 

JPMS / Jigsaw Support in XmlBeans 4.0

Repackaging the schema files

The schema generation has been modified in XmlBeans 4.0. Before the default path for the schemas was in schemaorg_apache_xmlbeans and the SchemaTypeSystem was fixed on the subdirectory structure.

With XmlBeans 4.0 this is now a bit more dynamic. The default generation will be in the package org.apache.xmlbeans.metadata, which should be adapted to the project package name.

This can be achieved by using the repackage options. Take the below example which is from the Apache POI build. The repackage option is changing the package structure from org.apache.xmlbeans.metadata to org.apache.poi.schemas.ooxml.

<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpath="${ooxml.xmlbeans.jar}"/>
<xmlbean
schema="${xmlbean.xsds.dir}"
srcgendir="${xmlbean.sources.dir}"
classgendir="${xmlbean.classes.dir}"
destfile="${xmlbean.xsds.dir}.jar"
srconly="true"
failonerror="true"
fork="true"
memoryMaximumSize="${ooxml.memory}"
typesystemname="ooxml"
repackage="org.apache.xmlbeans.metadata:org.apache.poi.schemas.ooxml">
<classpath>
<path location="${ooxml.xmlbeans.jar}"/>
</classpath>
</xmlbean>

The schema files are relatively addressed by the TypeSystemHolder instance under <repackage name>/system/<typesystemname> (e.g. /org/apache/poi/schemas/ooxml/system/ooxml)

Manual generation of module-info.java

The generation of the module-info.java isn't yet supported, hence you need to provide a module-info.java. In the case of Apache POI the module-info is injected as part of a multi-release configuration.

Example module-info.java

Depending on the used JDK version, specifically for Java 9 and 10 you might need to include xml-apis. More recent Java version work with the following dependency set:

open module <your-package-name> {
// this still throws "requires transitive directive for an automatic module" in JDK 14
// see https://bugs.openjdk.java.net/browse/JDK-8240847
requires transitive org.apache.xmlbeans;
requires java.xml;
exports <your-xml-schema-packages...>;
}

Currently it's necessary to open the schema classes module because of the dynamically loaded *.xsb files. This limitation might be obsolete in future versions of XmlBeans.