Invalid JAXP API when unmarshaling JAXB

samblake picture samblake · Aug 28, 2013 · Viewed 17.1k times · Source

I have a JAXB object I can unmarshal fine. However, if I add a Element[] field annotated with @XmlAnyElement, when attempting to unmarshal it throws:

java.lang.IllegalStateException: You are running with invalid JAXP api or implementation. JAXP api/implementation of version 1.3.1 (included in JDK6) or higher is required. In case you are using ant, make sure ant 1.7.0 or higher is used - older versions of ant contain JAXP api/impl version 1.2 (in xml-apis.jar). If you want to keep using older ant versions, you have to configure it to use higher the JAXP api/impl versions.

This is run from a TestNG test that I am running via the Eclipse plugin. I am running with the 1.6 JDK and configured maven to exclude old versions of the xml-apis jar however I can't seem to get it working. I assume I'm still picking up incompatible versions of the libraries from somewhere but don't know where from.

Running via Eclipse directly I get:

29-Aug-2013 10:04:08 com.sun.xml.bind.v2.util.XmlFactory createTransformerFactory
SEVERE: null
java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V
    at com.sun.xml.bind.v2.util.XmlFactory.createTransformerFactory(XmlFactory.java:155)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.createTransformerHandler(JAXBContextImpl.java:747)
    at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader$State.<init>(DomLoader.java:75)
    at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader.startElement(DomLoader.java:118)
    at com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:60)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:501)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:150)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:218)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:190)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
    at com.gtspt.vrs.parser.AbstractParserTest.unmarshal(AbstractParserTest.java:33)
    at com.gtspt.vrs.parser.AbstractParserTest.testParser(AbstractParserTest.java:26)
    at com.gtspt.vrs.parser.TestResultsParser.testParser(TestResultsParser.java:17)
    at com.gtspt.vrs.parser.Test.main(Test.java:16)

Answer

samblake picture samblake · Aug 29, 2013

It looks like the issue is due to an old version of Xalan. It seems a minimum of version 2.7.0 is needed since JDK 5. Another library was pulling in an older version so I excluded that from the Maven build and everything looks good now.