线程“main”中的异常java.lang.NoClassDefFoundError:org / openqa / selenium / WebDriver [英] Exception in thread "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>
我在我的pom.xml目录中运行
mvn clean install
我还根据Selenium文档在我的app类中导入了正确的类
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;
然而,当我尝试运行我的main方法时,我收到以下错误
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.
推荐答案
我在线程main中遇到过这个异常的经验java.lang.NoClassDefFoundError:org / openqa / selenium / WebDriver
错误并希望分享自己的解决方案:
I had experience with this Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
error and want to share own solution:
当我收到此错误时,我使用<$在IntelijIDEA中启动了我的应用程序编辑配置中的c $ c> Jar (让我们检查):
When I get this error, I launched my application in IntelijIDEA using Jar
in Edit Configuration (let's check):
错误是:
And the error was:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at project.Main.main(Main.java:45)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
所以,我添加而不是 Jar应用
- > 应用
:
< a href =https://i.stack.imgur.com/43kgj.png =nofollow noreferrer>
此处也发生了变化:
So, I added instead of Jar Application
-> Application
:
And here changed too:
它帮助我解决了错误。
注意:我的依赖关系就像
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
这篇关于线程“main”中的异常java.lang.NoClassDefFoundError:org / openqa / selenium / WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!