Groovy Grape处理依赖性解析 [英] Groovy Grape dealing with dependency resolution

查看:79
本文介绍了Groovy Grape处理依赖性解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use org.xhtmlrenderer:core-renderer:R8pre2 in a groovy script, but I get a Linkage error:

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

我已经在Google上搜索了很多,并找到了很多类似这样的答案:

I've already googled a lot and found a lot of answer like these:

处理"Xerces hell"在Java/Maven中?

与JavaSE 6内部冲突的XercesImpl实施.两者都需要...该怎么办?

因此,一种解决方案可能是使用Java的 endorsed 机制来解决冲突,但是我想使我的脚本独立于这种变通方法".该脚本应该立即可用.

So, one solution could be to use javas endorsed mechanism to resolve the conflict, but I would like to make my script independent from such a "workaround". The script should run out of the box.

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

Next thing I was giving a try was to exclude the right dependency like this

@Grapes([
    @Grab('org.xhtmlrenderer:core-renderer:R8pre2'),
    @GrabExclude('xml-apis:xml-apis')
])

但没有成功...

有什么想法吗?

PS:这是产生错误的脚本:

PS: here is the script which creates the error:

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

推荐答案

感谢@dmahapatro,我检查了配置,发现很久以前我在{usrhome}/.groovy中放了一些jar.删除了这些内容,现在一切都变得很迷人...

Thanx to @dmahapatro, I checked my configuration and found that I dropped some jars in {usrhome}/.groovy a long time ago. Removed these and now everything work like a charm...

这篇关于Groovy Grape处理依赖性解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆