0

Have been using JAXB and EXIficient library to marshall objects to XML then compress the XML to EXI. Able to send the EXI over the wire and recover the XML. The schemas and binding files reside under my projects src/main/resources/xsd folder. Able to run my prototype application successfully from IDE (Gradle, IntelliJ). Have packaged the app and resources into an uber/fat JAR and created a set of run scripts. Running app via the command line is failing when building the EXI grammar for the top-level XSD.

My initial snippet for the EXI factory setup looked like this:

var SCHEMA_PATH = "xsd/my-root.xsd";
var exiFactory = DefaultEXIFactory.newInstance();

URL xsdResource = EXICodec.class.getClassLoader().getResource(SCHEMA_PATH);
checkNotNull(xsdResource);
var xsdAbsPath = xsdResource.getFile();

// Following OK when run from within IDE.
// Following generates exception when trying to locate the XSD in uber JAR.
exiFactory.setGrammars(GrammarFactory.newInstance().createGrammars(xsdAbsPath));

exiFactory.getEncodingOptions().setOption(EncodingOptions.INCLUDE_COOKIE, true);
exiFactory.setCodingMode(CodingMode.COMPRESSION);

It failed as follows

com.siemens.ct.exi.core.exceptions.EXIException: XML Schema document (file:/mnt/c/Users/user1/my-project/tmp-install/myapp-0.1/lib/myapp-0.1.jar!/xsd/my-root.xsd) not found.

Basically, the XSD cannot be found in the uber/fat JAR. Looking at the JAR contents I saw the expected /xsd/my-root.xsd entry. Realized that I can't access the schema as a file as its not really a file but a resource bundled in the jar.

Tweaked my EXI factory setup as follows


exiFactory = DefaultEXIFactory.newInstance();

var xsdInputStream = ClassLoader.getSystemResourceAsStream(SCHEMA_PATH);

// Seeing exceptions as XSDs referenced from top-level XSD can't be located within JAR
exiFactory.setGrammars(GrammarFactory.newInstance().createGrammars(xsdInputStream));

exiFactory.getEncodingOptions().setOption(EncodingOptions.INCLUDE_COOKIE, true);
exiFactory.setCodingMode(CodingMode.COMPRESSION);

Got a bit further but ran into problems locating the XSDs referenced from my top-level XSD. E.g. entries such as the following in the top-level XSD s

<xs:import namespace="http://someURL/someVersion/" schemaLocation="../other/common.xsd"/>

led to errors like the following when creating the grammar

com.siemens.ct.exi.core.exceptions.EXIException: Problem occured while building XML Schema Model (XSModel)!
. [xs-warning] schema_reference.4: Failed to read schema document '../other/common.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

0 Answers0