【发布时间】:2014-05-26 02:38:46
【问题描述】:
我正在尝试在 groovy 脚本中使用 org.xhtmlrenderer:core-renderer:R8pre2,但出现链接错误:
Caught: java.lang.LinkageError: loader constraint violation in interface
itable initialization: when resolving method
"org.apache.xerces.dom.NodeImpl.getOwnerDocument()Lorg/w3c/dom/Document;"
the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the
current class, org/apache/xerces/dom/NodeImpl, and the class loader (instance of
<bootloader>) for interface org/w3c/dom/Node have different Class objects for
the type getOwnerDocument used in the signature
我已经用谷歌搜索了很多,并找到了很多这样的答案:
Dealing with "Xerces hell" in Java/Maven?
因此,一种解决方案可能是使用 javas endorsed 机制来解决冲突,但我想让我的脚本独立于这种“解决方法”。该脚本应该立即可用。
接下来我要尝试的是像这样排除正确的依赖项
@Grapes([
@Grab('org.xhtmlrenderer:core-renderer:R8pre2'),
@GrabExclude('xml-apis:xml-apis')
])
但没有成功...
有什么想法吗?
PS:这是产生错误的脚本:
@Grapes([
@Grab('org.xhtmlrenderer:core-renderer:R8pre2'),
])
import org.w3c.dom.Document
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
def dbf = DocumentBuilderFactory.newInstance()
DocumentBuilder builder = dbf.newDocumentBuilder()
Document doc = builder.parse(new ByteArrayInputStream("<html></html>".getBytes()))
【问题讨论】:
-
提供的脚本没有出现任何错误。
[#document: null]是结果。 Groovy 2.2.1 -
刚刚再试一次,我得到了错误。
Groovy Version: 2.2.2 JVM: 1.7.0_09 Vendor: Oracle Corporation OS: Windows 8。所以可能是我的配置有问题... -
更新了 groovy 和 java - 仍然是同样的问题...