PCJ-XPathFactoryImpl not found when running in Groovy scripts

Problem

Sometimes when using Project Configurator in Groovy scripts you get an error like this:

java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: Provider org.apache.xpath.jaxp.XPathFactoryImpl not found at java.xml/javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:119)

You can still use the UI to work with Project Configurator and create export zips. The problem is related to the Groovy execution and has no relation with the Project Configurator functionality.

Reason

In some cases the implementation for XPathFactory is missing and it cannot be loaded during the Groovy execution in the workflow export phase.

Solution

The Java API for XML Processing interfaces enable you to plug in your own implementation of XPathFactory.

You can do this by adding a new system property like this:

-Djavax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom=com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl

You can find more information in this article.