[英]JDK6 -> JDK7 cant use com.sun.xml.internal.stream.XMLInputFactoryImpl
we have the following case in the code which causes tests to fail when running with JAVA_HOME set to JDK7 instead of JDK6 (maven with source/target = 1.6) 我们的代码中有以下情况,当将JAVA_HOME设置为JDK7而不是JDK6时,导致测试失败(源/目标= 1.6的Maven)
javax.xml.stream.FactoryConfigurationError: Provider for com.sun.xml.internal.stream.XMLInputFactoryImpl cannot be found
at javax.xml.stream.XMLInputFactory.newFactory(XMLInputFactory.java:239)
the code itself 代码本身
private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
private final XMLInputFactory xmlInputFactory;
public theConstructor() {
// When deployed to WebLogic 10.3.5 it will use "weblogic.xml.stax.XMLStreamInputFactory" which will
// cause a StreamReader exception as it requires some input stream other than null.
xmlInputFactory = XMLInputFactory.newFactory(SUN_XML_INPUT_FACTORY, this.getClass().getClassLoader());
}
I suppose I should use something else than private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
我想我应该使用private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
之外的其他东西private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
but i don't know what. 但是我不知道
I found after JDK6, the method: 我在JDK6之后发现了该方法:
javax.xml.stream.XMLInputFactory.newFactory(String factoryId,ClassLoader classLoader)
change it's program. 改变它的程序。
The parameter factoryId
is not a classpath, but a key. 参数factoryId
不是类路径,而是键。
So I put a stax.properties
file into my $java.home/jre/lib/
file and the context is: 所以我将stax.properties
文件放入$java.home/jre/lib/
文件中,上下文为:
com.bea.xml.stream.MXParserFactory=com.bea.xml.stream.MXParserFactory
then my problem solved. 然后我的问题解决了。
XMLInputFactory factory = XMLInputFactory.newFactory("com.bea.xml.stream.MXParserFactory", this.getClass().getClassLoader());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.