java.lang.NoClassDefFoundError:com/google/common/collect/ImmutableMap,同时在Java Selenium中将WebDriver与Maven依赖项一起使用

java.lang.NoClassDefFoundError:com/google/common/collect/ImmutableMap,同时在Java Selenium中将WebDriver与Maven依赖项一起使用

问题描述:

  1. 这是driver=new ChromeDriver();行之后的代码的一部分,它给我我用sysout检查的错误,错误在2中,那么我使用Maven的经验不是很好,但是我正在检查我的pom.xml文件,我给了Selenium依赖项.
  1. It is portion the code after driver=new ChromeDriver(); line it give me error i check with sysout, errors are in the 2, well i am not well experienced using Maven but i am checking my pom.xml file , i gave Selenium dependencies.

-有什么建议吗?有任何帮助吗?

-Any advice?, any helps appreciated

public WebDriver initilizeDriver() throws IOException
{
    Properties prop= new Properties();
    FileInputStream fıs=new FileInputStream("C:\\Users\\Melih Sancak\\my-amazonTest\\src\\main\\java\\com\\ObjectRepisotary\\app\\data.properties");
    prop.load(fıs);
    String browserName =prop.getProperty("browser");
    System.out.println(browserName);
    if(browserName.equals("chrome"))
    {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Melih Sancak\\Downloads\\chromedriver.exe");
        driver=new ChromeDriver();
    }
}

2.错误:

java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:253)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.<init>(ChromeDriverService.java:94)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)

文件com/google/common/collect/ImmutableMap可能已损坏:

部署Maven项目会抛出Java .util.zip.ZipException:无效的LOC标头(错误的签名)

如果您使用的是eclipse,并且要检查此文件是否已损坏,请尝试将其打开.它位于番石榴Maven依赖项中.如果它已损坏,则会显示invalid LOC header (bad signature).

If you are using eclipse and want to check whether this file is corrupted just try to open it. It is located in the guava maven dependency. If it is corrupted it will show you invalid LOC header (bad signature).

然后找到.m2文件夹,搜索损坏的文件并将其删除.最后运行一个Maven更新.

Then locate the locate the .m2 folder, search for the corrupted file and delete it. Finally run a maven update.

那为我解决了这个问题.

That solved the problem for me.