XMLBeans change default generated .xsb files location

1.3k Views Asked by At

OK so I have a main application that uses XMLBeans 3.0. I'm trying to create a self contained JVM using Java10 and Jlink. So I use scomp command to generate my Java classes based on some XSD file and I name this JAR say custom.jar. I opened custom.jar and noticed that scomp places the .xsb files under this package:

 schemaorg_apache_xmlbeans.system.s2CA052CB375796887D9B5CB20D4C89AC

Now my JLink project also depends on xbean.jar. And it seems that this JAR also has a package like this similar to custom.jar:

schemaorg_apache_xmlbeans.system

So I compile main project and create a JVM runtime image using JLink. Then I'm able to bring up my application.
Problem is that during runtime my application references a class from my custom.jar, I'm getting a missing file error. Looking at the stacktrace it seems that the classloader is trying to find my custom .xsb file under the xbean.jar, but of course it doesn't exist on that JAR.

I'm not too familiar how classloading works especially now in Java10/modules, but anyone knows a way to fix this issue?

These are the exports from module-info xbean.jar for that package path in question:

exports schemaorg_apache_xmlbeans.system.sXMLCONFIG;
exports schemaorg_apache_xmlbeans.system.sXMLLANG;
exports schemaorg_apache_xmlbeans.system.sXMLSCHEMA;
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;

These are the exports for my custom.jar for that similar package path:

exports schemaorg_apache_xmlbeans.system.s2CA052CB375796887D9B5CB20D4C89AC;

Below is the stacktrace but looking at the xbean.jar source code this is the line that cannot find the .xsb file:

SchemaTypeSystemImpl.this._resourceLoader.getResourceAsStream(resourcename);

Maybe a modification in any of the module-info files or how to tell scomp to change the default schemaorg_apache_xmlbeans.system package ?

Thank in advance.

        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.RuntimeException: Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?
        at custom/schemaorg_apache_xmlbeans.system.sD4E93FD3AF9AB0042ABA3EB739A1C5B8.TypeSystemHolder.loadTypeSystem(Unknown Source)
        at custom/schemaorg_apache_xmlbeans.system.sD4E93FD3AF9AB0042ABA3EB739A1C5B8.TypeSystemHolder.<clinit>(Unknown Source)
        ... 48 more
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
        ... 50 more
Caused by: org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD4E93FD3AF9AB0042ABA3EB739A1C5B8/index.xsb (schemaorg_apache_xmlbeans.system.sD4E93FD3AF9AB0042ABA3EB739A1C5B8.index) - code 0
        at xbean/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1519)
        at xbean/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:273)
        at xbean/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:185)
        ... 54 more
0

There are 0 best solutions below