JAXP XSLT transformer using wrong implementation by default

风格不统一 提交于 2019-12-23 10:28:11

问题


I've got a Tomcat 5.5 web application that uses the Apache Commons-Configuration library to generate an XML configuration file at runtime. Commons-Configuration, in turn, uses the javax.xml.transform JAXP API to accomplish this.

Since upgrading to Java 7, the operation fails with the following error message:

Caused by: javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
    at javax.xml.transform.TransformerFactory.newInstance(Unknown Source)

In past releases, I've never bundled xalan.jar, instead relying on the platform default XSLT implementation.

Some things I've checked:

  • There are no META-INF/services/javax.xml.transform.TransformerFactory entries in any of my application JAR files, library jars, or in the Tomcat jars
  • The javax.xml.transform.TransformerFactory system property is unset (verified at runtime through JVisualVM)
  • There is no jaxp.properties file in the jre/lib directory

Running with -Djaxp.debug=1 produces the following output:

JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: loaded from fallback value: org.apache.xalan.processor.TransformerFactoryImpl

Where's this fallback value coming from? Oracle ships the Xalan transformer, but since 1.7 has repackaged it as com.sun.org.apache.xalan.processor.... Shouldn't that be the fallback value?


回答1:


Found the issue myself. It turns out that I had the apache-tomcat-5.5.23-compat files installed, as I was migrating from Java 1.4.2. The solution was to remove everything under the $CATALINA_HOME/common/endorsed directory (in particular xercesImpl.jar and xml-apis.jar) and the bin/jmx.jar files.




回答2:


The same issue i was also getting with Glassfish server V3.1 and by placing xalan-2.7.0.jar in $GLASSFISH_HOME\lib\endorsed directory the issue is resolved.



来源:https://stackoverflow.com/questions/12284131/jaxp-xslt-transformer-using-wrong-implementation-by-default

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!