phax / phive

Generic business document validation engine
Apache License 2.0
42 stars 12 forks source link

Failed to create JAXB context for package 'oasis.names.specification.ubl.schema.xsd.invoice_21' #23

Closed ghost closed 2 months ago

ghost commented 2 months ago

There are a few other questions like this on this thread, please forgive me if this is repetitive, but maybe the versions matter.

I'm using Java 1.8 (I cannot change this) and therefore using this Gradle dependencies:

implementation 'com.helger.ubl:ph-ubl21:6.7.0'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.2'

My Gradle wrapper is 7.5.1

My unit tests pass when running in the IntelliJ Gradle window, but not when calling ./gradlew test from the command line. When running from the command line, the system throws an exception on this line:

final InvoiceType ubl2_1Object = UBL21Reader.invoice().read(document);

With the stack trace:

{"timestamp":"2024-08-23 16:37:31,668","level":"ERROR","class":"com.myclass","log":{"message":"java.lang.IllegalArgumentException: Failed to create JAXB context for package 'oasis.names.specification.ubl.schema.xsd.invoice_21' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@6a6824be
    at com.helger.jaxb.JAXBContextCacheKey._createFromPackageAndClassLoader(JAXBContextCacheKey.java:165)
    at com.helger.jaxb.JAXBContextCacheKey.createJAXBContext(JAXBContextCacheKey.java:202)
    at com.helger.jaxb.JAXBContextCache.lambda$new$0(JAXBContextCache.java:81)
    at com.helger.commons.cache.MappedCache.getFromCache(MappedCache.java:337)
    at com.helger.jaxb.JAXBContextCache.getFromCache(JAXBContextCache.java:124)
    at com.helger.jaxb.JAXBContextCache.getFromCache(JAXBContextCache.java:166)
    at com.helger.jaxb.builder.AbstractJAXBBuilder.getJAXBContext(AbstractJAXBBuilder.java:164)
    at com.helger.jaxb.builder.JAXBReaderBuilder.createUnmarshaller(JAXBReaderBuilder.java:134)
    at com.helger.jaxb.builder.JAXBReaderBuilder.read(JAXBReaderBuilder.java:165)
    at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:366)
...
...
Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory not found
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:151)

I'm wondering if I have some runtime parameters that are missing or if it's a dependency. I would imagine if the document truly does not abide by UBL21 standards the IntelliJ tests would fail as well.

Any ideas from anyone? Thanks to all for maintaining this project.

ghost commented 2 months ago

I found this StackOverflow page. It seems I'm very close, and I am using Jakarta for my own annotations for my own classes, but none touch this code.

ghost commented 2 months ago

Please close this ticket as it was opened under the wrong project. Apologies for the mistake.

phax commented 2 months ago

To my knowledge Jakarta runtime requires Java 11