Project

Profile

Help

What is the recommended way to prevent Saxon from making itself the default XPath and Transformer object model?

Added by Brian Inouye over 10 years ago

We have implemented a new feature in our Java application that wishes to use Saxon Professional Edition as its XPath processor. We have added saxon-9.4.0.1.jar and saxon-license.lic to our application's classpath. However, this now makes Saxon the default object model for XPathFactory and TransformerFactory, which breaks some of the existing features. To minimize risk, we want Saxon to not inject itself as the default object model. What is the recommended way to achieve this? We tried removing the files javax.xml.transform.TransformerFactory and javax.xml.xpath.XPathFactory from saxon-9.4.0.1.jar, and this seems to have the desired effect, but we do not know if this is a safe thing to do.


Replies (1)

RE: What is the recommended way to prevent Saxon from making itself the default XPath and Transformer object model? - Added by Michael Kay over 10 years ago

Removing the files META-INF/services/javax.xml.transform.TransformerFactory and META-INF/services/javax.xml.xpath.XPathFactory certainly will have the desired effect, and no adverse effects other than what you would expect from having two different versions of the same JAR file around. It also means the Saxonica signature on the JAR file will no longer be valid, which might be relevant with some ClassLoaders.

I don't think this should be necessary. Setting the system property javax.xml.transform.TransformerFactory to the name of the JAXP provider you want to use by default should be enough in most situations.

Incidentally, your description of the problem ("Saxon injecting itself as the default...") isn't really an accurate description of what's going on. The manifest in Saxon's JAR file declares that it provides a JAXP service, and by putting this JAR file on the class path, you are making it eligible to be selected when a JAXP provider is required. Saxon doesn't do anything actively to influence the search path. The JAXP provider that is chosen depends on the position of different JAR files in the class path. It's a horribly clumsy mechanism, I agree, but the real solution is that applications that care about what JAXP provider they are using should load the one they require explicitly.

    (1-1/1)

    Please register to reply