We have mutliple java web applications that are hosted with tomcat. Some of the applications include xercesImpl jars and others do not include xercesImpl.jar.
For the sake of simplicity, let say we have only two applications :
- xxx.war -> uses xerces
- yyy.war -> do not use xerces
Both applications do some xml parsing at boot time, and only java.* and javax.* are used (no direct import of org.apache.xerces).
What happens is if xxx.war starts first, than yyy.war with get an error while trying to parse xml :
Caused by: 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 ca.icod.personne.adressePostale.RecuperateurFormat.createXMLReader(RecuperateurFormat.java:246)
at ca.icod.personne.adressePostale.RecuperateurFormat.parse(RecuperateurFormat.java:214)
... 127 more
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1856)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1705)
at org.xml.sax.helpers.NewInstance.newInstance(NewInstance.java:82)
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:228)
When the applications starts in the reverse order, no problem at boot time. What I assume is happening is that when xxx.war starts, xercesImpl is found and so it's internal META-INF/services folder is read and therefore xerces is marked as the xml implementation to use in the JVM. And then when yyy.war try to dot xml stuff, the JVM still think it should use xerces but this time it's not on the classpath : ClassNotFoundException
We would like to proggressively remove xerces from our apps because the default implementations of the jdk seems to do the job.
But we hardly can remove xerces everywhere in one shot or separate our tomcat servers that hosts xerces enabled webapps from those hosting xercesless webapps.
Do I miss something odd or does someone here resolved similar issue ?