gpt4 book ai didi

java - 解码 JAXB 时无效的 JAXP API

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:43:40 25 4
gpt4 key购买 nike

我有一个可以解码的 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 构建之外,现在一切看起来都不错。

关于java - 解码 JAXB 时无效的 JAXP API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18493541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com