【问题标题】:java.lang.NoClassDefFoundError: com/google/common/collect/Maps - Seleniumjava.lang.NoClassDefFoundError: com/google/common/collect/Maps - Selenium
【发布时间】:2013-09-08 13:27:07
【问题描述】:

尊敬的 Selenium 专家,

我从一个 JPA 2.0 程序中遇到以下运行时错误,由于某种原因,该程序似乎与 Firefox Profile 有关:

线程“主”java.lang.NoClassDefFoundError 中的异常:com/google/common/collect/Maps 在 org.openqa.selenium.firefox.FirefoxProfile.(FirefoxProfile.java:56) 在 org.openqa.selenium.firefox.FirefoxProfile.(FirefoxProfile.java:79) 在 model.DownloadCarDetail.getMercedezDetail(model.DownloadCarDetail:72) 在 model.DownloadCarDetail.getMercedezDetail.main (model.DownloadCarDetail.getMercedezDetail.java:47) 引起:java.lang.ClassNotFoundException:com.google.common.collect.Maps 在 java.net.URLClassLoader$1.run(URLClassLoader.java:366) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:355) 在 java.security.AccessController.doPrivileged(本机方法) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 4 更多 Java 结果:1

我将 Firefox 保持在版本 15,以便 Selenium Webdriver 支持它,但怀疑问题与无法读取配置文件目录有关。

非常感谢您的帮助。

非常感谢,

乔治

【问题讨论】:

    标签: selenium-webdriver


    【解决方案1】:

    您看到的问题与您的 Firefox 配置文件无关。

    其实是JVM类加载器报错找不到com.google.common.collect.Maps类。

    这通常意味着您的类路径中没有 Guava(这是 Selenium 的依赖项)。清理并重建您的项目,检查您的类路径,检查可能存在的各种版本的库。如果您正在使用某种依赖管理系统(Maven、Ivy 等),请检查它的配置是否正确。

    【讨论】:

      【解决方案2】:

      导入从here下载的 .jar 文件到 Eclipse(取决于当前版本)。

      【讨论】:

      • 从此链接下载 jar 文件并将其添加到类路径解决了我的问题
      【解决方案3】:

      打开此链接https://www.seleniumhq.org/download/ 并下载 Java 3.11.0(当前版本)在 netbeans 或 eclips 上打开 zip 文件到桌面单击在 selenium-java-3.11.0\libs 中添加 jars/文件选择所有文件也在 selenium- java-3.11.0 选择 client-combined-3.11.0.jar 就可以了。不要记得添加System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); 代码。你可以下载chromedriver这个链接https://chromedriver.storage.googleapis.com/index.html?path=2.38/

      【讨论】:

      • 在哪里添加这一行 --> System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
      【解决方案4】:

      就我而言,Guava 依赖项已损坏。在我删除损坏的 jar 并重建整个项目后工作正常。

      【讨论】:

        【解决方案5】:

        感谢您提出解决此问题的建议。我从Selenium 2 WebDriver NoClassDefFoundErrorS 找到了确切的答案,它已经解决了根本问题。

        乔治

        【讨论】:

          【解决方案6】:

          在下面添加 maven 依赖项并清理和编译您的代码。

          <!-- https://mvnrepository.com/artifact/com.google.common/google-collect -->
          <dependency>
              <groupId>com.google.common</groupId>
              <artifactId>google-collect</artifactId>
              <version>0.5</version>
          </dependency>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-04-06
            • 1970-01-01
            • 2022-10-07
            • 2020-09-12
            • 2018-10-14
            • 2020-09-16
            • 2018-01-18
            • 2018-05-26
            相关资源
            最近更新 更多