I have run into some problems with the Xerces library, which is used by a third party lib that I rely on.
Xerces does not support JAXP 1.5, yet, which is contained in recent releases of JDK 1.7 and JDK 8. This leads to some problems, if Xerces is used as the XML parser, which can happen when several XML parsers are known to the system. Removing xercesImpl-v2.9.0.jar
immediately fixes the problem, but then the 3rd party library isn't working anymore.
I can see two solutions to the problem:
It seems that the only bit from the Xerces library that is actually used is the org.apache.xerces.util.XMLCatalogResolver
, used in CustomResolver.java
. Are there other options for the catalog resolver instead of the Xerces one?
Another option seems to be to explicitly set the system properties for XML parsing at JVM launch. That way the JVM can told which XML parser to use and it wouldn't select Xerces anymore.
I found the following three properties:
-Djavax.xml.transform.TransformerFactory
-Djavax.xml.parsers.SAXParserFactory
-Djavax.xml.parsers.DocumentBuilderFactory
This leads to two questions, though:
Indeed, setting those three system properties would allow you to set the JAXP implementation to use at runtime.
This will not help you if you use a 3rd-party library that has explicit dependency on Xerces, which seems to be the case for you (as you wrote, removing xerces
from the Classpath causes one of your 3rd-party libraries to break).
So, first, decide whether you can avoid using that 3rd-party library, and use a replacement library that doesn't have a hard dependency on Xerces. As JAXP is quite mature now, the only reasonable scenario for a hard dependency on Xerces is if your 3rd-party library uses some very specific Xerces functionality for the purpose of its job.
If you can avoid using that 3rd-party library, then do so.
Otherwise, you can set these three system properties, and keep Xerces in the classpath. What will happen then is:
There still is a chance that you'll run into problems, if there are classloading-related conflicts between Xerces and your new parser. In that case, you're pretty much out of luck, I'm afraid (unless you can somehow ensure that the two usages of the two parsers are done under different classloaders).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With