I was struggling to add HtmlUnit to Grails to do some testing when I came upon this.
The solution was to remove the HtmlUnit included jar, xml-apis-1.3.04.
The error looked like this:
loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/w3c/dom/NamedNodeMap" java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/NamedNodeMap" at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2427) at java.lang.Class.getMethod0(Class.java:2670) at java.lang.Class.getMethod(Class.java:1603) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.isDom3Present(ContextFactory.java:301) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.getE4xImplementationFactory(ContextFactory.java:328) at net.sourceforge.htmlunit.corejs.javascript.Context.getE4xImplementationFactory(Context.java:2175) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.initStandardObjects(ScriptRuntime.java:222) at net.sourceforge.htmlunit.corejs.javascript.Context.initStandardObjects(Context.java:1069) at net.sourceforge.htmlunit.corejs.javascript.Context.initStandardObjects(Context.java:1036) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.init(JavaScriptEngine.java:157) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$000(JavaScriptEngine.java:68) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.run(JavaScriptEngine.java:130) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize(JavaScriptEngine.java:141) at com.gargoylesoftware.htmlunit.WebClient.initialize(WebClient.java:1107) at com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage(WebWindowImpl.java:99) at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:268) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:127) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:442) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:371) at UIUnitTests.setUp(UIUnitTests.groovy:12) at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:202) at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:146) at _GrailsTest_groovy$_run_closure1_closure19.doCall(_GrailsTest_groovy:112) at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:95) at TestApp$_run_closure1.doCall(TestApp:66) at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:344) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:334) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.processTargets(Gant.groovy:495) at gant.Gant.processTargets(Gant.groovy:480)
7 Comments
I had the same problem, this helped me out, thanks!
That helped me too. Thanks for sharing.
Thanks for working that out, I’ve been stumped by it for hours until I found this page.
Got a different error message, but same solution indeed. Thanks! And nice page BTW.
Thanks for posting this. It am not sure I would have traced down the problem.
I had the same error in the same class in Pentaho’s Kettle. I was dreading searching through all of the jars for the culprit. Thanks for the help!
HTMLUnit depends on some XML processing libraries that cause issues with Grails. You can avoid this by excluding certain dependencies of the HTMLUnit driver…
1
2
3
test(“org.seleniumhq.selenium:selenium-htmlunit-driver:«webdriver version»”) {
exclude ‘xml-apis’
}
Post a Comment