Groovy Grape dealing with dependency resolution

旧时模样 提交于 2019-12-23 20:09:13

问题


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

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

Dealing with "Xerces hell" in Java/Maven?

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

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')
])

but didn't succeed...

Any ideas?

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

回答1:


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...



来源:https://stackoverflow.com/questions/23021082/groovy-grape-dealing-with-dependency-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!