我们有使用tomcat托管的多个java Web应用程序。 一些应用程序包括xercesImpl jar,其他应用程序不包含xercesImpl.jar。
为简单起见,我们假设只有两个应用程序:
两个应用程序在引导时都进行一些xml解析,并且只使用java。*和javax。*(不直接导入org.apache.xerces)。
如果xxx.war首先启动,yyy.war会在尝试解析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)
当应用程序以相反的顺序启动时,启动时没有问题。 我假设发生的是当xxx.war启动时,找到xercesImpl,因此读取内部的META-INF / services文件夹,因此xerces被标记为要在JVM中使用的xml实现。然后当yyy.war尝试点xml时,JVM仍然认为它应该使用xerces但这次它不在类路径上:ClassNotFoundException
我们希望从我们的应用程序中逐步删除xerces,因为jdk的默认实现似乎可以完成这项工作。
但我们几乎无法一次性删除xerces,或者将托管xerces的webcat的tomcat服务器与托管xercesless webapps的托管服务器分开。
我是否想念一些奇怪的事情,或者有人在这里解决了类似问题吗?