SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver)
Added by Vladimir Nesterovsky almost 3 years ago
I'm trying to run Saxon 11.1 in batch environment (GitHub action) and get error shown below. I think it uses Java 15 or 16. It was working with Saxon 10.6.
Error:
[java] [1]:java.util.concurrent.CompletionException: javax.xml.transform.TransformerFactoryConfigurationError: Provider for class javax.xml.transform.TransformerFactory cannot be created
[java] [1] at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
[java] [1] at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
[java] [1] at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1803)
[java] [1] at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1792)
[java] [1] at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
[java] [1] at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
[java] [1] at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
[java] [1] at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
[java] [1] at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
[java] [1] Caused by: javax.xml.transform.TransformerFactoryConfigurationError: Provider for class javax.xml.transform.TransformerFactory cannot be created
[java] [1] at java.xml/javax.xml.transform.FactoryFinder.findServiceProvider(FactoryFinder.java:293)
[java] [1] at java.xml/javax.xml.transform.FactoryFinder.find(FactoryFinder.java:247)
[java] [1] at java.xml/javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:126)
[java] [1] ... 6 more
[java] [1] Caused by: java.lang.RuntimeException: Provider for class javax.xml.transform.TransformerFactory cannot be created
[java] [1] at java.xml/javax.xml.transform.FactoryFinder.findServiceProvider(FactoryFinder.java:290)
[java] [1] ... 11 more
[java] [1] Caused by: java.util.ServiceConfigurationError: javax.xml.transform.TransformerFactory: Provider net.sf.saxon.TransformerFactoryImpl could not be instantiated
[java] [1] at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:584)
[java] [1] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:806)
[java] [1] at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:724)
[java] [1] at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1396)
[java] [1] at java.xml/javax.xml.transform.FactoryFinder$1.run(FactoryFinder.java:276)
[java] [1] at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
[java] [1] at java.xml/javax.xml.transform.FactoryFinder.findServiceProvider(FactoryFinder.java:271)
[java] [1] ... 11 more
[java] [1] Caused by: java.lang.NoClassDefFoundError: org/xmlresolver/Resolver
[java] [1] at net.sf.saxon.lib.CatalogResourceResolver.<init>(CatalogResourceResolver.java:46)
[java] [1] at net.sf.saxon.Configuration.init(Configuration.java:366)
[java] [1] at net.sf.saxon.Configuration.<init>(Configuration.java:229)
[java] [1] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[java] [1] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
[java] [1] at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[java] [1] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
[java] [1] at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
[java] [1] at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350)
[java] [1] at java.base/java.lang.Class.newInstance(Class.java:645)
[java] [1] at net.sf.saxon.Configuration.newConfiguration(Configuration.java:245)
[java] [1] at net.sf.saxon.s9api.Processor.<init>(Processor.java:69)
[java] [1] at net.sf.saxon.jaxp.SaxonTransformerFactory.<init>(SaxonTransformerFactory.java:59)
[java] [1] at net.sf.saxon.TransformerFactoryImpl.<init>(TransformerFactoryImpl.java:42)
[java] [1] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[java] [1] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
[java] [1] at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[java] [1] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
[java] [1] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
[java] [1] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:782)
[java] [1] ... 16 more
[java] Java Result: -1
Can you please point me what to look at?
Replies (63)
Please register to reply
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Andrew Dunning over 1 year ago
This remains an issue with Saxon 12.2. If one is using GitHub Actions and wants to make Saxon available using Maven, it cannot find xmlresolver, even when it is in the same directory. The workaround is to use java -cp
.
This is my pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.saxon</groupId>
<artifactId>Saxon test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>12.2</version>
</dependency>
</dependencies>
</project>
I am setting up Java in the GitHub Action using this:
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Get dependencies with Maven
run: mvn -f .github/workflows/pom.xml dependency:copy-dependencies
The Maven log confirms that Saxon is copied to .github/workflows/target/dependency/Saxon-HE-12.2.jar
and xmlresolver to .github/workflows/target/dependency/xmlresolver-5.1.2.jar
. I would have expected the usual java -jar
command for running Saxon to work in this case, but I instead receive the error in this thread.
One needs instead to specify the location of xmlresolver manually:
- name: XSLT transformation
run: java -cp ".github/workflows/target/dependency/Saxon-HE-12.2.jar:.github/workflows/target/dependency/xmlresolver-5.1.2.jar" net.sf.saxon.Transform -xsl:test.xsl -o:test.out test.xml
Note that a colon is required between the paths, not a semicolon (the syntax for Windows) as in previous replies.
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Michael Kay over 1 year ago
The manifest in the Saxon-HE-12.2.jar references the resolver as lib/xmlresolver-5.1.2.jar
- that is, it's not looking in the same directory, it's looking for it in a sibling directory named lib
. If that sibling directory doesn't exist or doesn't contain the xmlresolver jar, it won't find it, and you have to add whatever location actually contains it to your classpath by hand.
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh over 1 year ago
This remains an issue with Saxon 12.2. If one is using GitHub Actions and wants to make Saxon
available using Maven, it cannot find xmlresolver, even when it is in the same directory. The
workaround is to use java -cp.
If you add the resolver as a dependency to your project, does that
resolve the issue? I use Saxon in Github Actions all the time…
Be seeing you,
norm
--
Norm Tovey-Walsh
Saxonica
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg over 1 year ago
Can we please have a saxon.jar that behaves like a normal Java citizen, i. e. searching for ist dependencies as siblings not as children in fancy subfolders? Thanks! 😊
-Markus
Von: Saxonica Developer Community notifications@plan.io
Gesendet: Mittwoch, 17. Mai 2023 14:03
An: [Quipsy] Markus Karg karg@quipsy.de
Betreff: [Saxon - Help - msg8478] RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver)
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Andrew Dunning over 1 year ago
Thank you for your replies: manually specifying xmlresolver as a dependency does not have any effect. This makes sense, since Saxon does so itself. I would second Markus's suggestion to have Saxon search for dependencies in its own directory as well, given that this is Maven's assumption.
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh over 1 year ago
Thank you for your replies: manually specifying xmlresolver as a dependency does not have any
effect. This makes sense, since Saxon does so itself. I would second Markus's suggestion to have
Saxon search for dependencies in its own directory as well, given that this is Maven's
assumption.
I can probably arrange that for the next build. TBH, I thought lib/
was the canonical place. I guess conventions and tastes vary.
Be seeing you,
norm
--
Norm Tovey-Walsh
Saxonica
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh over 1 year ago
Thank you for your replies: manually specifying xmlresolver as a dependency does not have any
effect.
I’m not a maven expert, but I’m confused by that. If you ask Maven to
use xmlresolver as a dependency, I would expect it to appear on the
classpath. What am I missing?
Be seeing you,
norm
--
Norm Tovey-Walsh
Saxonica
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg over 1 year ago
I am a Maven Expert so I hope I can clarify for you: Maven puts all explicitly declared dependencies (including explicit transient dependencies) on the classpath, but does not guarantee that the created classpath has any particular folder structure. If you expect to find a JAR in a particular folder or expect that a JAR has a particular file name, Maven cannot know this and will not respect these expectations. Hence you should follow the best practices of both worlds:
- Do not expect particular file names or folder structures.
- Do not load JAR files, but load Classes. Let the Classloader do its job.
- Let Maven do what Maven wants to do. Do not try to convince Maven to do something you want.
- When building a JAR let Maven compute the Manifest (do not use a hand-written Manifest). Tell Maven to include the Class-Path: entry in the Manifest that it has computed. It will be flat without any folder structure.
-Markus
Von: Saxonica Developer Community notifications@plan.io
Gesendet: Mittwoch, 17. Mai 2023 14:45
An: [Quipsy] Markus Karg karg@quipsy.de
Betreff: [Saxon - Help - msg8478] RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver)
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Andrew Dunning over 1 year ago
Many thanks indeed! Maven installs all dependencies in the same directory by default regardless of where they are specified; hence it installs xmlresolver in the same place regardless of whether it knows it as a dependency from the local pom.xml
or from Saxon's. One can override the directory to which the dependencies are installed (e.g. -DoutputDirectory=./lib
) but then everything ends up in the lib
directory and Saxon cannot find xmlresolver in that case either.
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh over 1 year ago
I am a Maven Expert so I hope I can clarify for you: Maven puts all explicitly declared
dependencies (including explicit transient dependencies) on the classpath, but does not guarantee
that the created classpath has any particular folder structure.
I apologize if I’m being slow, but that explanation doesn’t help me
understand what’s going on. The Saxon jar file that you can download
from saxonica.com includes a few libraries in a lib/ directory and uses
the manifest to amend the classpath so that they will be found if, for
example, you just run
java -jar saxon-xxx.jar …
That works and is, AFAIK, the only real reason why those extra libraries
are included in the distribution.
For the Maven distributed releases, Saxon merely asserts a dependency on
those libraries, including the XML Resolver. As long as they’re all on
the classpath, it should work. Or if it doesn’t work, I don’t understand
why.
For example, I have a (Gradle) build script that uses Maven to collect
Saxon and its dependencies together. When I run a transformation with
that build script, the following jar files appear on the classpath:
/Users/ndw/.gradle/caches/modules-2/files-2.1/org.docbook/docbook-xslTNG/2.1.2/30176102747e00105a6362490b8af5e2e361c5fb/docbook-xslTNG-2.1.2.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/org.relaxng/jing/20220510/a6409bfe2bf28fe6e7c3c92f0e31131003346007/jing-20220510.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/com.nwalsh/sinclude/5.2.4/6227dcab03f65c993b16664241b28234ab9b20ff/sinclude-5.2.4.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/net.sf.saxon/Saxon-HE/11.5/ca94def74001be04cb0d1199e2cb36feaa7da08b/Saxon-HE-11.5.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/org.docbook/schemas-docbook/5.2CR5/36e03047ebec96a923ead1cf514b3c30bc4d12b1/schemas-docbook-5.2CR5.jar
/Users/ndw/.m2/repository/org/xmlresolver/xmlresolver/5.1.2/xmlresolver-5.1.2.jar
/Users/ndw/.m2/repository/org/xmlresolver/xmlresolver/5.1.2/xmlresolver-5.1.2-data.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/com.drewnoakes/metadata-extractor/2.18.0/fa9fd43a28b10333108c603819810d5176d2b092/metadata-extractor-2.18.0.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/org.relaxng/trang/20220510/6e9f2cdef29fe57b12ef8abe19160dce2ac4a748/trang-20220510.jar
/Users/ndw/.m2/repository/org/apache/httpcomponents/client5/httpclient5/5.1.3/httpclient5-5.1.3.jar
/Users/ndw/.m2/repository/org/apache/httpcomponents/core5/httpcore5-h2/5.1.3/httpcore5-h2-5.1.3.jar
/Users/ndw/.m2/repository/org/apache/httpcomponents/core5/httpcore5/5.1.3/httpcore5-5.1.3.jar
/Users/ndw/.gradle/caches/modules-2/files-2.1/com.adobe.xmp/xmpcore/6.1.11/852f14101381e527e6d43339d7db1698c970436c/xmpcore-6.1.11.jar
/Users/ndw/.m2/repository/isorelax/isorelax/20030108/isorelax-20030108.jar
/Users/ndw/.m2/repository/xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar
/Users/ndw/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar
/Users/ndw/.m2/repository/commons-codec/commons-codec/1.15/commons-codec-1.15.jar
My transformation proceeds without any problems. What is different in
our environments?
Be seeing you,
norm
--
Norm Tovey-Walsh
Saxonica
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Michael Kay over 1 year ago
Well, I'm certainly NOT an expert in this area!
But when you say:
For the Maven distributed releases, Saxon merely asserts a dependency on those libraries, including the XML Resolver. As long as they’re all on the classpath, it should work.
I don't understand how that will make "java -jar" work, since my understanding was that when you use "java -jar", the classpath is ignored.
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg over 1 year ago
I have not checked the source code within it, so I cannot tell you if you’re doing something wrong when trying to load the dependency, but looking at the JAR itself found in Maven Central then I noticed at least the following untypical things:
- The POM file references dependencies without scope. If XML Resolver is not needed at compile time but only at runtime, it should have a scope of runtime. As I have not checked your source code I cannot tell you if that is the cause.
- The JAR apparently was not created using Maven, as it does not contain Maven metainformation. It is long time ago that I found a JAR on Maven Central that was not created by Maven, but I doubt that is a problem.
- The JAR’s Manifest does not contain a Class-Path: entry. Hence it will not be able to find xml-resolved when started with -jar.
- When trying to fix Maven issues you should actually use Maven for test drives, not Gradle. While they share some things, to are largely different.
HTH
-Markus
Von: Saxonica Developer Community notifications@plan.io
Gesendet: Mittwoch, 17. Mai 2023 15:42
An: [Quipsy] Markus Karg karg@quipsy.de
Betreff: [Saxon - Help - msg8478] RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver)
RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg over 1 year ago
Clarification:
„java -jar“ will ignore „-cp“ and the Maven Classpath, hence it is essentially dependend of the Class-Path: entries found in the JAR’s Manifest file. As the Saxon JAR found on Maven Central does not contain a Class-Path: entry in the manifest, this CANNOT work.
-Markus
Von: Saxonica Developer Community notifications@plan.io
Gesendet: Mittwoch, 17. Mai 2023 15:56
An: [Quipsy] Markus Karg karg@quipsy.de
Betreff: [Saxon - Help - msg8478] RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver)
- « Previous
- 1
- 2
- 3
- Next »
Please register to reply