线程“main"中的异常java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver [英] Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

查看:86
本文介绍了线程“main"中的异常java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 pom.xml 中添加了最新的 Selenium 依赖

I have added the most updated Selenium dependency in my pom.xml

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.7.1</version>
</dependency>

我跑了mvn 全新安装在我的 pom.xml 目录中,我还根据 Selenium 文档在我的应用程序类中导入了正确的类

I ran mvn clean install inside the directory with my pom.xml and I have also imported the correct classes in my app class as per the Selenium documentation

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

但是,当我尝试运行主方法时,出现以下错误

However when i try and run my main method, I get the following error

Exception in thread "main" java.lang.NoClassDefFoundError: 
org/openqa/selenium/WebDriver

我查看 ~/.m2/repository 文件夹,但没有看到 openqa 文件夹,而是看到了 seleniumhq 文件夹.

I look in my ~/.m2/repository folder and I don't see an openqa folder but instead I see a seleniumhq folder.

为什么 maven 不安装 openqa 文件夹,为什么文档说从 org.openqa 导入...而我的 jar 存储库中从未存在过.我很困惑,我只想在我的本地存储库中成功导入 selenium Webdriver.

Why didn't maven install the openqa folder, and why does the documentation say to import from org.openqa... when that never exist in my jar repository. I'm very confused, I just want to be able to import selenium Webdriver successfully while having it in my local repository.

推荐答案

在 Eclipse IDE 中遇到此错误.在 Eclipse 中,转到项目属性,在 Java Build Path 中,只需在 Classpath 而不是 Modulepath 中添加 selenium jar.然后在顶部的 Project 选项卡下执行 Clean 以删除早期的构建,然后执行 Run.

Encountered this error in Eclipse IDE. In Eclipse go to Project properties and in Java Build Path just add selenium jars in Classpath instead of Modulepath. Then under the Project tab on the top do a Clean to remove earlier buiid and then do a Run.

这篇关于线程“main"中的异常java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆