Groovy Grape处理依赖性解析

时间:2014-04-11 19:28:17

标签: groovy xerces grape

我正在尝试在groovy脚本中使用org.xhtmlrenderer:core-renderer:R8pre2,但我收到了Linkage错误:

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?

XercesImpl in conflict with JavaSE 6's internal xerces implementation. Both are needed... what can be done?

所以,一个解决方案可能是使用javas endorsed机制来解决冲突,但我想让我的脚本独立于这样的&#34;解决方法&#34;。该脚本应该是开箱即用的。

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

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

1 个答案:

答案 0 :(得分:1)

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