我有以下代码:
javax.xml.transform.TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
javax.xml.transform.Transformer transformer = factory.newTransformer();
这可以正常工作。但是,我还需要将Xalan作为依赖项添加到我的pom.xml中,当我这样做时,上面的代码现在抛出一个错误:
java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalDTD
我认为这与Xalan的jar中有一个不同的Transformer实现有关。如何才能在不更改上述代码并保留Xalan依赖项的情况下解决此冲突?
发布于 2017-07-18 05:17:48
从Xalan中排除Xerces可以解决此问题:
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.2</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
发布于 2020-10-15 11:41:59
需要按如下方式设置系统级属性
System.setProperty("javax.xml.transform.TransformerFactory","com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
发布于 2019-05-22 03:23:00
对我有效的解决方案是这样做:
compile('org.opensaml:opensaml:2.6.1') {
exclude group: 'xerces', module: 'xercesImpl'
exclude module: 'xalan'
}
https://stackoverflow.com/questions/45152707
复制相似问题