1

While upgrading Java 7 to Java 8 in my webapplication I am having this problem with Saxon:

javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: jar:file:/C:/Users/abc/.m2/repository /net/sf/saxon/saxon-xpath/9.1.0.8/saxon-xpath-9.1.0.8.jar!/META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax at java.util.ServiceLoader.fail(ServiceLoader.java:239) at java.util.ServiceLoader.fail(ServiceLoader.java:245) at java.util.ServiceLoader.parseLine(ServiceLoader.java:265) at java.util.ServiceLoader.parse(ServiceLoader.java:307) at java.util.ServiceLoader.access$200(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357) at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393) at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474) at javax.xml.xpath.XPathFactoryFinder$2.run(XPathFactoryFinder.java:345) at javax.xml.xpath.XPathFactoryFinder$2.run(XPathFactoryFinder.java:341) at java.security.AccessController.doPrivileged(Native Method) at javax.xml.xpath.XPathFactoryFinder.findServiceProvider(XPathFactoryFinder.java:341) at javax.xml.xpath.XPathFactoryFinder._newFactory(XPathFactoryFinder.java:212) at javax.xml.xpath.XPathFactoryFinder.newFactory(XPathFactoryFinder.java:137) at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:190)

I upgraded saxon to Saxon HE but it doesnt work:

Q{java:org.apache.commons.lang3.StringUtils}isBlank(). Reflexive calls to Java methods are not available under Saxon-HE

at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:261) at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:107) at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:785) at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:149)

Moving to licensed Saxon PE or other is out of the question :/

I am not sure why but the application uses XpathFactory like that:

XPath xpath = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON).newXPath();

I don't know why this object model had been chosen, not for example OBJECT_MODEL_DOM4J

I am wondering if:

1) There is some free for commercial use saxon that would work in Java 8 ? I doesn't have to be the newest one, we are using 9.1.0.8 or 9.1.0.6J.

2) What is this NamespaceConstant.OBJECT_MODEL_SAXON, is it possible to resign from Saxon and move to OBJECT_MODEL_DOM4J and use dom4j instead or maybe there is other way to implement something like that using free library?

XPath xpath = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON).newXPath();
                xpath.setNamespaceContext(new NamespaceContextMap("a12i", "http://my-application/a12"));
                return xpath.compile(MY_XPATH_QUERY);
stephanmathew
  • 241
  • 3
  • 13

1 Answers1

1

You can find information about this problem here

Syntax error in javax.xml.xpath.XPathFactory provider-configuration file of Saxon-HE 9.3

and in various threads referenced from there. The essence of it is that earlier releases of Saxon used a format for the services file (supporting the XPathFactory JAXP search mechanism) that worked in Java 5 and didn't work in subsequent Java releases (Saxon was inadvertently dependent on a bug in Java that was subsequently fixed).

As you point out, moving from Saxon-B (9.1) to Saxon-HE can be problematic because some features, notably reflexive extension functions, were not carried forward. However, there are alternative ways of achieving the same effect in later releases without the security problems associated with reflexive extension functions.

If you want to stick with Saxon-B (9.1) you can probably get it to work on newer Java releases by changing the call on XPathFactory.newInstance() to instantiate the Saxon XPathFactory directly. The choice of object model is irrelevant to the problem.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164