Project

Profile

Help

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

Added by Vladimir Nesterovsky 6 months 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 (40)

Please register to reply

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

I cannot know where Maven locates the dependency JARs on an arbitrary machine.

Other option is to use maven-dependency-plugin to copy all dependencies into the target folder, so ant will know where to look at.

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

Thank you! Your proposals made my day! :-)

In fact, I am meanwhile using an even simpler solution that does not deal with files at all but passes the classpath as a property:

<plugin>
  <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>dependency-class-paths</id>
        <phase>validate</phase>
        <goals>
          <goal>build-classpath</goal>
        </goals>
        <configuration>
          <outputProperty>classpath</outputProperty>
        </configuration>
      </execution>
    </executions>
</plugin>
<java classname="net.sf.saxon.Transform" classpath="${classpath}" logError="true" fork="true" taskname="xsl">
  <arg value="-o:@{out}" />
  <arg value="-s:@{in}" />
  <arg value="@{style}" />
</java>

While this is a nice workaround, the actual solution would be to convince the maven-antrun-plugin to promote the dependency classpath to ant implicitly (just like it promotes Maven properties as ANT properties). Doing so, nobody would need to invest any effort into such a tedious and error-prone workaround. Hence I hope the Maven people accept my feature proposal: https://issues.apache.org/jira/browse/MANTRUN-237. :-)

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

While this is a nice workaround, the actual solution would be to convince the maven-antrun-plugin to promote the dependency classpath to ant implicitly (just like it promotes Maven properties as ANT properties). Doing so, nobody would need to invest any effort into such a tedious and error-prone workaround.

Chances for this change are near zero. This is for two reasons:

  • ant is not in favor any more, so no one wants to invest into it.
  • this is not compatible change, which might impact existing solutions, provided they will upgrade the version.

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

As a frequent Maven contributor I need to disagree.

  • I could do the change on my own, just as I did a lot of times with other Maven plugins in the past, so committers are just bothered for review and voting.
  • This is a compatible change as soon as it is opt-in using a new configuration property.

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

While this is a nice workaround, the actual solution would be to
convince the maven-antrun-plugin to promote the dependency classpath
to ant implicitly (just like it promotes Maven properties as ANT

I’d like to figure out what Saxon is doing that’s not working for you
and see if we can fix that for the next release. I use Maven
(indirectly, through Gradle) all the time and I’ve never had any trouble
resolving the XML Resolver jars.

Something about your environment is different and if I can get a test
case that reproduces it, I might be able to fix it.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

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

I doubt that there is anything wrong with Saxon itself. The problem is either ANT not forwarding the classpath to the java ant task, or Maven antrun plugin not forwarding the dependency classpath to ANT. I assume it is the latter.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Alan Painter about 2 months ago

Late to the party but I'm also running into this from the java command line (no maven, just straight java).

  • using Java11 (yes, a bit old, but LTS still current)
  • using the jar Saxon-HE-11.3.jar

(N.B. This command line works with Saxon-HE-10.5.jar)

java -jar Saxon-HE-11.3.jar -xsl:source.xslt -s:source.xml -o:output.xml

and I get the famous "java.lang.NoClassDefFoundError: org/xmlresolver/Resolver"

I understand from this that I won't be able to use the -jar shortcut with 11.3 but instead I'll have to construct the classpath with multiple jars from the command line.

That's too bad as it was a nice shortcut with a single jar.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Martin Honnen about 2 months ago

That is kind of odd, I am using the Java 11 and Saxon-HE-11.3.jar pretty much like you do and never run into problems related to the resolver.

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

Hi Alan,

  • using Java11 (yes, a bit old, but LTS still current)
  • using the jar Saxon-HE-11.3.jar

(N.B. This command line works with Saxon-HE-10.5.jar)

java -jar Saxon-HE-11.3.jar -xsl:source.xslt -s:source.xml -o:output.xml

and I get the famous "java.lang.NoClassDefFoundError:
org/xmlresolver/Resolver"

Where did you get the Saxon-HE-11.3.jar from?

If you got it from our downloads, then when you unpacked it, there
should also be a lib directory next to it. The resolver and a few other
jars are in that lib directory.

If you moved it without copying the lib directory, or if you grabbed the
Saxon Jar file out of some Maven cache, then that’s probably the
problem.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Alan Painter about 2 months ago

Hi Norman,

I do understand that the xmlresolver jar can be retrieved separately and added to the classpath.

What I'm mentioning and perhaps not conveying is that, whereas one could previously run this command line to run a transform:

java -jar Saxon-HE-10.5.jar -xsl:source.xslt -s:source.xml -o:output.xml

one must now run this other command line (unless I am missing something fundamental, in which case I would be ecstatic to be enlightened):

java -cp "Saxon-HE-11.3.jar;xmlresolver-4.3.0.jar" net.sf.saxon.Transform -xsl:source.xslt -s:source.xml -o:output.xml

Be sure to know that I'm not complaining. I'm an avid saxon enthusiast and evangelist and I appreciate your work more than you probably could imagine.

I'm mentioning this "feature regression" here just so that you are aware that there is an impact on command-line running of Saxon. Im not blocked, but a little sad that, unless I am mistaken, one can no longer run a transform from java with simply the " -jar " flag.

And in all cases, thanks for the help and the good work.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Martin Honnen about 2 months ago

If you install/unzip the HE 11 zip from Sourceforge into some directory on your computer (e.g. C:\Program Files\Saxonica\SaxonHE11J) and then run e.g. java -jar C:\Program Files\Saxonica\SaxonHE11J\Saxon-HE-11.3.jar -xsl:source.xslt -s:source.xml -o:output.xml you can run with the -jar option and Saxon finds its libraries (like the resolver) in the lib subfolder of the installation directory.

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Alan Painter about 2 months ago

Hi Martin,

I appreciate the suggestion.
I'm really looking for the -jar XX.jar solution without having to prepare an unzipped directory beforehand.

The two-jar-classpath solution will work.

Thanks and best regards

-alan

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

Saxonica Developer Community writes:

I appreciate the suggestion. I'm really looking for the -jar XX.jar
solution without having to prepare an unzipped directory beforehand.

I’m confused, Alan. You have somehow obtained and downloaded the Saxon
jar file. If you got that from Maven, the POM file included should point
your system to the relevant dependencies. If you got that from a ZIP
file that you downloaded from one of our repositories, then it will have
included the relevant jar files in the lib directory as Martin suggests.

If you have taken just the jar file (either from Maven or from our ZIP)
and discarded or ignored the ancillary information in the POM file or
the other files in the ZIP, then…well, yes, I guess it won’t work. But
why would you do that?

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Alan Painter about 1 month ago

Hi Norman,

I'm also a little confused at explaining something that I thought was self-evident but, upon reflexion, I realize that it's perhaps a question of very different work contexts.

Within banks and other hyper-secure environments, one can't download zip files from Saxonica. I also can't plug in a USB stick. Verboten. The bank wants to make sure that no unwanted artifacts make it into the bank's network, hence everything is "vetted" before being brought in. Certain artifacts from maven central, once vetted for vulnerabilities and licenses, are retrieved into internal repositories. Everything that I retrieve is necessarily piecemeal, jar by jar, pulled out of the internal artifact repository. For builds, this poses no problem, because maven/gradle will retrieve all of the dependencies. But there are many instances where I want to run a transformation from the command line outside of a maven project. With Saxon-HE-10.5, I was using "-jar" for that.

An example of a use outside of maven/gradle: When deploying applications with complex configurations, especially with environment-specific and even cluster-specific properties, I'll often use XSLT to generate the various documents (files) that make up the installed configuration. This is typically performed directly in the remote environment which will not have maven/gradle installed. Previously, I could do this by including only the Saxon-10.5.jar with the delivered bundle for remote execution on a deployment platform. Now I'll be delivering other jars with it and making the command line a little bit more complicated.

I've mentioned that it's nothing of a showstopper, but just not quite as convenient as it was previously with a single, self-contained jar.

I was curious about Martin's mention of "java -jar" finding the xmlresolver-4.2.0 jar by itself. I wasn't able to reproduce this in my local environment. Comparing the the Saxon-HE.11.3.jar's manifest from the internal repository and from the Saxon website (using my personal kit), I see that there is a difference: the Class-Path declaration is missing from the internal jar. I don't know exactly why that is .. I suspect that it's another security "feature" that is applied when the maven-central artifacts are retrieved to the internal artifact repository.

So this explains why I was not able to reproduce Martin's automatic discovery of xmlresolver.jar using the "-jar" option within the bank.

Personally, I'm ecstatic that Saxon-HE.11.3.jar has made it into the internal repository, even without the Class-Path declaration in the manifest.

I hope that this clears up the "why I would want to" part, albeit verbosely.

I understand the reason to not bundle everything in the saxon jar, hence I'll have to accept this evolution in my command-line-launched transformations.

thanks and best regards

-alan

RE: SaxonHE 11.1 (java.lang.NoClassDefFoundError: org/xmlresolver/Resolver) - Added by Norm Tovey-Walsh about 1 month ago

I've mentioned that it's nothing of a showstopper, but just not quite
as convenient as it was previously with a single, self-contained jar.

Fair enough. You’re setting up a very bespoke environment so it’s not
surprising that you have to manage the classpath a little more
carefully.

I was curious about Martin's mention of "java -jar" finding the
xmlresolver-4.2.0 jar by itself. I wasn't able to reproduce this in my
local environment. Comparing the the Saxon-HE.11.3.jar's manifest from
the internal repository and from the Saxon website (using my personal
kit), I see that there is a difference: the Class-Path declaration is
missing from the internal jar. I don't know exactly why that is .. I
suspect that it's another security "feature" that is applied when the
maven-central artifacts are retrieved to the internal artifact
repository.

Actually, I just looked and it appears the classpath is removed as part
of publishing it to Maven. That’s not too surprising really since if
you’re using Maven, you expect Maven to manage the classpath for you.
Having random extra changes applied by jar files could definitely make
“classpath hell” even worse.

I hope that this clears up the "why I would want to" part, albeit
verbosely.

Yep. Thanks.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

(26-40/40)

Please register to reply