Viktor Mellgren
Viktor Mellgren

Reputation: 4506

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)

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"; but i don't know what.

Upvotes: 2

Views: 3848

Answers (1)

Steven
Steven

Reputation: 11

I found after JDK6, the method:

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

change it's program.

The parameter factoryId is not a classpath, but a key.

So I put a stax.properties file into my $java.home/jre/lib/ file and the context is:

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

Upvotes: 1

Related Questions