java 使用 XPathFactory 的类路径问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/798333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Classpath issue using XPathFactory
提问by B.E.
I keep getting the following exception on one of our live servers (the others running the same code seem ok):
我在我们的一台实时服务器上不断收到以下异常(其他运行相同代码的服务器似乎没问题):
java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/domwith the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:67)
I'm pretty sure that I have the Xalan and Saxon jars in the classpath (using IBM Java 1.5).
我很确定我在类路径中有 Xalan 和 Saxon jar(使用 IBM Java 1.5)。
Do you have any Ideas what else could be wrong?
你有什么想法还有什么可能是错的?
Edit:
编辑:
That's the code that causes the Problem:
这是导致问题的代码:
XPathFactory factory = XPathFactory.newInstance();
And it's running on a custom web server that's roughly based on the catalina engine.
它运行在大致基于 catalina 引擎的自定义 Web 服务器上。
采纳答案by B.E.
Found the answer myself: The problem is the combination of using Java 5 and having an option
我自己找到了答案:问题是结合使用 Java 5 和有一个选项
-Djava.endorsed.dirs
set to a directory that contained the xalan.jar.
设置为包含 xalan.jar 的目录。
Once removed everything works again.
删除后,一切都会恢复正常。
回答by FiveO
You need to add the appropriate .jar in your classpath. In my case I used the Saxon-HE library.
您需要在类路径中添加适当的 .jar。就我而言,我使用了 Saxon-HE 库。
There exists a bug in Saxon9 you maybe run into like me.
The bug has been corrected in version 9.5.1.5. So you may download the latest Saxon 9 HE.
该错误已在 9.5.1.5 版中得到纠正。所以你可以下载最新的 Saxon 9 HE。
回答by Ichorus
Make sure you have the appropriate xml-apis.jar and xerces jars in your classpath for the version of xalan that you are using (check the release notes for what, exactly, you need). Also make sure you don't have multiples as the xercesImpl.jar, xml-apis.jar and xalan.jar need to be in sync.
确保您的类路径中有适合您正在使用的 xalan 版本的 xml-apis.jar 和 xerces jar(请查看发行说明以了解您需要的确切内容)。还要确保您没有倍数,因为 xercesImpl.jar、xml-apis.jar 和 xalan.jar 需要同步。

