我试图在Netbeans平台项目中使用webdrive,但我一直收到以下错误:
java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.gargoylesoftware.htmlunit.html.DomNode.getAttributes()Lorg/w3c/dom/NamedNodeMap;" the class loader (instance of org/netbeans/StandardModule$OneModuleClassLoader) of the current class, com/gargoylesoftware/htmlunit/html/DomNode, and the class loader (instance of <bootloader>) for interface org/w3c/dom/Node have different Class objects for the type 3c/dom/NamedNodeMap; used in the signature
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:187)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:476)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:454)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:180)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:190)
at geo.parser.GeocacheParser.getNextPage(GeocacheParser.java:102)
at geo.DetailsTopComponent.btnLoadPlus20ActionPerformed(DetailsTopComponent.java:250)
at geo.DetailsTopComponent.access$200(DetailsTopComponent.java:61)
at geo.DetailsTopComponent$3.actionPerformed(DetailsTopComponent.java:125)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch]
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
WARNING [org.netbeans.TopSecurityManager]: use of system property netbeans.home has been obsoleted in favor of InstalledFileLocator/Places at org.netbeans.Clusters.relativeDirsWithHome(Clusters.java:137)
有人可以帮忙吗?
答案 0 :(得分:0)
您的类路径中有不同版本的org / w3c / dom / NamedNodeMap。
您应该检查项目构建首选项,因为对于一个项目,您可能具有相同的xml-apis-X.YZ.jar两次(具有不同的版本)。 (但我检查了我的项目依赖项.... selenium-server-standalone-2.41.0.jar也包含这个类。)
解决方案是从类路径中删除此类文件的错误版本。一种解决方法是手动删除未使用的jar文件。 (或将jar范围设置为提供)
<强>更新强>
使用此方法显示项目类路径:
void displayClassPath() {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
do {
URL[] urls = ((URLClassLoader)classloader).getURLs();
for(URL url: urls){
System.out.println(url.getFile());
}
classloader = (URLClassLoader)classloader.getParent();
} while(classloader != null);
}
您可以在文件系统中找到NamedNodeMap类文件的所有实例(在列出的jar文件中)。尝试排除无效/已弃用/旧版本。
...或者......另一种方法是使用JVM选项-verbose。它显示所有已加载的JAR文件和类(和接口)。
[Loaded org.openqa.selenium.io.FileHandler$NoFilter from file:/C:/Program%20Files/Java/jre7/lib/ext/selenium-java-2.41.0.jar]
[Loaded java.nio.channels.ReadableByteChannel from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.nio.channels.ByteChannel from C:\Program Files\Java\jre7\lib\rt.jar]
例如:我在Eclipse中有一个Selenium项目,我使用了displayClassPath()方法。在类路径中创建了三个NamedNodeMap实例,在这些jar文件中具有相同的签名:
(要检查签名,您可以反编译.class文件:http://jd.benow.ca/)
有关它的一些链接:
答案 1 :(得分:0)
对于其他收到此错误的人,因为我认为到目前为止还没有充分解释:
如前所述,rt.jar包含此类,它是Java运行时本身。 因此,如果您将xml-apis jar作为依赖项或任何其他依赖项将其作为依赖项,您将收到该错误。
Gradle的修复(但可以很容易地插入到任何其他java构建工具中),htmlunit用作示例,但它可以是任何其他依赖项:
compile('net.sourceforge.htmlunit:htmlunit:2.27' ){
exclude group: 'xml-apis', module: 'xml-apis'
}
查找依赖项运行
gradle dependencies
问题是因为gradle确实无法将xml-apis与rt.jar进行比较,所以它不会进行版本检查,通常你可以在这里看到:
\--- xerces:xercesImpl:2.9.1 -> 2.11.0
->
表示xerces已被更新版本取代以避免冲突,因为另一个依赖项已经在使用更新的版本。