在NetBeans平台项目中使用的webdriver链接错误(Linkage error using

2019-11-03 04:47发布

我想在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)

[抓住]

    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)

任何人都可以帮忙吗?

Answer 1:

你在你的类路径不同版本的组织/ W3C / DOM /的NamedNodeMap的。

您应该检查你的项目建立的喜好,因为你可能有相同的XML的API-X.YZ.jar两次(不同版本)一个项目。 (但是,我检查了我的项目依赖....硒的服务器独立-2.41.0.jar包含这个类也。)

解决的办法是消除类路径这类文件的版本错误。 一个解决办法是手动删除未使用的jar文件。 (或设置的罐子范围提供

更新:

显示项目的classpath用这种方法:

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中硒的项目,我使用的displayClassPath()方法。 NamedNodeMap中的三个实例中成立了与这些jar文件相同签名的类路径:

  • 硒的服务器独立,2.41.0.jar
  • XML的API-1.4.01.jar
  • jre7 \ LIB \ rt.jar中

(要检查签名,你可以反编译.class文件: http://jd.benow.ca/ )

有关它的一些链接:

  • http://www.ibm.com/developerworks/java/library/j-dyn0429/
  • http://ma.juii.net/blog/java-lang-linkageerror-between-two-jar-files
  • 如何处理Java中LinkageErrors?


Answer 2:

对于其他人,因为我不相信这是足够至此说明谁得到这个错误:

正如前面提到的rt.jar包含这个类是Java运行时本身。 因此,如果你有XML的API罐子的依赖或任何其他依赖它作为依赖,你会得到这个错误。

用于摇篮的修复(但可以很容易地插值到任何其他Java构建工具),是的HtmlUnit用作一个例子,但它可以是任何其它依赖性:

compile('net.sourceforge.htmlunit:htmlunit:2.27' ){
    exclude group: 'xml-apis', module: 'xml-apis'
}

为了找到依赖运行

gradle dependencies

问题是,因为它的gradle不能rt.jar中也不会做版本检查比较XML的API,通常你可以怎么在这里看到:

   \--- xerces:xercesImpl:2.9.1 -> 2.11.0

->说的Xerces用较新版本替换,因为另一依赖已经在使用最新版本,以避免冲突。



文章来源: Linkage error using webdriver in a Netbeans platform project