JDK6 - > JDK7无法使用com.sun.xml.internal.stream.XMLInputFactoryImpl

时间:2014-10-02 10:46:52

标签: java maven java-7 jdk6

我们在代码中有以下情况导致测试在JAVA_HOME设置为JDK7而不是JDK6(maven with source / target = 1.6)的情况下运行时失败

javax.xml.stream.FactoryConfigurationError: Provider for com.sun.xml.internal.stream.XMLInputFactoryImpl cannot be found
        at javax.xml.stream.XMLInputFactory.newFactory(XMLInputFactory.java:239)

代码本身

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());
}

我想我应该使用除private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl";以外的其他东西,但我不知道是什么。

1 个答案:

答案 0 :(得分:0)

我在JDK6之后找到了方法:

javax.xml.stream.XMLInputFactory.newFactory(String factoryId,ClassLoader classLoader)

改变它的计划。

参数factoryId不是类路径,而是键。

所以我将stax.properties文件放入我的$java.home/jre/lib/文件中,上下文是:

com.bea.xml.stream.MXParserFactory=com.bea.xml.stream.MXParserFactory

然后我的问题解决了。

XMLInputFactory factory = XMLInputFactory.newFactory("com.bea.xml.stream.MXParserFactory", this.getClass().getClassLoader());
相关问题