Project

Profile

Help

SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver)

Added by Vladimir Nesterovsky about 2 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 - Added by Michael Kay about 2 years ago

The key message in the stack trace is

Caused by: java.lang.NoClassDefFoundError: org/xmlresolver/Resolver

So the XmlResolver needs to be on your classpath. It's in the lib directory of the download directory, and should be picked up because it's referenced in the manifest of the main JAR file; but we haven't used that mechanism before so I don't know if it works in all environments. (It certainly won't work if you move the JAR files somewhere else.)

RE: SaxonHE 11.1 - Added by Vladimir Nesterovsky about 2 years ago

I have a maven project that refers SaxonHE. I do not directly refer xml resolver artifact, but I shall try to.

GitHub runner sets up all jdk and maven by itself, so it is kind of clean environment.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Vladimir Nesterovsky about 2 years ago

Maven's pom https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/11.1/Saxon-HE-11.1.pom declares zero dependencies.

Can you please point to a public maven artifact exposing org.xmlresolver.Resolver?

RE: SaxonHE 11.1 - Added by Norm Tovey-Walsh about 2 years ago

Saxonica Developer Community writes:

I have a maven project that refers SaxonHE. I do not directly refer
xml resolver artifact, but I shall try to.

The jar files shipped to Maven failed to correctly identify the fact
that the XML Resolver is a required dependency.

I am working on fixing that, and a couple of other minor build issues,
and will very likey publish an 11.1.1.

Apologies for the inconvenience.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Alexander Stein almost 2 years ago

Is this still an issue in 11.3? I just attempted to build a container for an updated use of XSpec and encountered this issue.

https://github.com/xspec/docker/pull/2

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Michael Kay almost 2 years ago

org.resolver.XmlResolver is a required dependency in 11.3. Saxon tries to pick it up automatically from a the folder containing the main JAR file, but if it isn't there, and isn't on the classpath, you will get a failure.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh almost 2 years ago

Saxonica Developer Community writes:

Is this still an issue in 11.3? I just attempted to build a container
for an updated use of XSpec and encountered this issue.

As Michael said, you will need the XML Resolver jars. You will also need
this PR for XSpec:

https://github.com/xspec/xspec/pull/1610

(Or some equivalent workaround.)

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Alexander Stein almost 2 years ago

Thanks to both of you, I had workaround code to pull in the resolver in an explicit classpath with both JAR files. It was the XSpec bug (fixed by xspec/xspec#1610) that was causing me to pull my hair out last night and was wondering what I was missing. Thank you!

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg almost 2 years ago

Unfortunately the class org.xmlresolver.Resolver still is not found by Maven even with Saxon-HE 11.3. As soon as your project's pom.xml depends on saxon he 11.3 once you use maven-antrun-plugin, and in build.xml use the xsl task, then you will see the stack trace again. Apparently, the saxon dependency itself is found by the xsl task, but not its transitive dependency xmlresolver. I did not find any workaround other than stick to saxon he 10.8. Not even directly adding xmlresolver as a dependency parallel to saxon he did fix it! I assume that the mechanism used to pick up xmlresolver within saxon expects something that is not true for antrun plugin.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Vladimir Nesterovsky almost 2 years ago

We do call Saxon 11.3 from apach ant and it works for us.

Please consider using task to explicitly help resolving class path. See https://ant.apache.org/manual/using.html

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg almost 2 years ago

As I said, I suppose the problem is located in Maven ANT Run Plugin.
-Markus

Von: Saxonica Developer Community
Gesendet: Mittwoch, 8. Juni 2022 10:13
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 almost 2 years ago

Do you use latest Maven plugins and latest JDK 18 as I do?
How do you resolve the path as you suggested when running maven ant run plugin?
-Markus
P.S. „It works for me" actually is not of any actual help for people where it does not work. 😉

Von: Saxonica Developer Community
Gesendet: Mittwoch, 8. Juni 2022 10:46
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 Vladimir Nesterovsky almost 2 years ago

We use GitHub action that runs maven that runs ant that executes xslt transformation with Saxon 11.3. It uses Java 15.

„It works for me" actually is not of any actual help for people where it does not work.

My answer assumes that this setup (maven -> ant -> Saxon 11.3) may work. Other my advice was to use path ant task to specify all class path dependencies - it seems this is what it makes working for me.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg almost 2 years ago

How do you use path ant task from within Maven Antrun Plugin? I cannot know where Maven locates the dependency JARs on an arbitrary machine.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Michael Kay almost 2 years ago

„It works for me" actually is not of any actual help for people where it does not work.

All data points are useful. Knowing that a solution exists at least means it's worth pursuing.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg almost 2 years ago

Michael, the fact that it works at some arbitrary location does not mean that this is a solution, but only that the problem is dependent on something nobody knows of.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Michael Kay almost 2 years ago

I didn't say it was a solution, I said it was helpful because it tells us that a solution is possible.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Vladimir Nesterovsky almost 2 years ago

How do you use path ant task from within Maven Antrun Plugin? I cannot know where Maven locates the dependency JARs on an arbitrary machine.

Following is purely specific to my setup, so not sure it's relevant for you:

  1. Maven explicitly refers resolver jar.

  2. Maven has following to have a list of dependencies in file:

    maven-dependency-plugin dependency-class-paths validate build-classpath ${project.build.directory}/dependencies.txt
  3. Ant configures all dependencies using relative paths and substitutions, where ${dependencies} refers to dependencies.txt:

  <loadfile property="dependencies" srcFile="${common.build}\..\..\dependencies.txt" failonerror="false" />

  <!-- Project common class path. -->
  <path id="project.classpath">
    <pathelement path="${java.class.path}" />
    <pathelement path="${common.build}\..\.." />
    <pathelement path="${dependencies}" />
    <fileset dir="${common.build}\..\.." includes="*.jar" />
  </path>

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Vladimir Nesterovsky almost 2 years ago

      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>dependency-class-paths</id>
            <phase>validate</phase>
            <goals>
              <goal>build-classpath</goal>
            </goals>
            <configuration>
              <outputFile>${project.build.directory}/dependencies.txt</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Markus Karg almost 2 years ago

Can you please post that section of your project's POM where it uses maven-dependency-plugin to create the file "dependencies.txt"? Thanks. :-)

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh almost 2 years ago

Saxonica Developer Community writes:

[[PGP Signed Part:Undecided]]

(1-25/63)

Please register to reply