3

我正在尝试org.xhtmlrenderer:core-renderer:R8pre2在 groovy 脚本中使用,但出现链接错误:

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

我已经用谷歌搜索了很多,并找到了很多这样的答案:

在 Java/Maven 中处理“Xerces hell”?

XercesImpl 与 JavaSE 6 的内部 xerces 实现发生冲突。两者都需要......可以做什么?

因此,一种解决方案可能是使用 javasendorsed机制来解决冲突,但我想让我的脚本独立于这种“解决方法”。该脚本应该开箱即用。

接下来我尝试的是像这样排除正确的依赖项

@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()))
4

1 回答 1

2

感谢@dmahapatro,我检查了我的配置,发现很久以前我在 {usrhome}/.groovy 中放置了一些 jar。删除了这些,现在一切都像魅力一样工作......

于 2014-04-11T20:32:14.093 回答