Problems with Xerces and Jenkins

Rationale TL;DR

Out of nowhere some Jenkins jobs decide to stop working, with errors like:

java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:543)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at org.xml.sax.helpers.NewInstance.newInstance(NewInstance.java:82)
	at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:228)
Caused: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
	at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:230)
	at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:191)
	at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.<init>(XmlResponsesSaxParser.java:120)
Caused: com.amazonaws.SdkClientException: Couldn't initialize a SAX driver to create an XMLReader
	at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.<init>(XmlResponsesSaxParser.java:123)
	at com.amazonaws.services.s3.model.transform.Unmarshallers$InitiateMultipartUploadResultUnmarshaller.unmarshall(Unmarshallers.java:315)
	at 

Solution

The issue here is that some pluing (usually the S3 or plugin-aws require the xerces jar available. There are two actions to fix this issue:

  • First one is to tell Jenkins to use its internal SAX implementation. To do that add [1] to the Jenkins startup flags (on Debian/Ubuntu, edit /etc/defaults/jenkins)
  • Second one is to download xerces 2.9.0 and put it on the plugin classpath (i.e. /var/lib/jenkins/pipeline-aws/WEB-INF/lib)

[1] -Dorg.xml.sax.driver=com.sun.org.apache.xerces.internal.parsers.SAXParser