java – 解组JAXB时无效的JAXP API

前端之家收集整理的这篇文章主要介绍了java – 解组JAXB时无效的JAXP API前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个JAXB对象,我可以解组很好.但是,如果我添加一个使用@XmlAnyElement注释的Element []字段,则在尝试解组时会抛出:

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.

这是通过我通过Eclipse插件运行的TestNG测试运行的.我正在运行1.6 JDK并配置maven以排除旧版本的xml-apis jar但是我似乎无法让它工作.我假设我仍然从某个地方拾取不兼容的库版本,但不知道从哪里来.

直接通过Eclipse运行我得到:

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)

解决方法

看起来这个问题是由旧版本的Xalan造成的.从JDK 5开始,似乎需要最低版本2.7.0.另一个库提供了旧版本,因此我将其从Maven构建中排除,现在一切看起来都很好.
原文链接:https://www.f2er.com/java/127207.html

猜你在找的Java相关文章