如何解决我的Java代码仅在从IDE运行时才有效,而在终端上不起作用
我可以在IDE中正常运行Java程序,但是当我在命令行中尝试此第一步时:
-
javac Main.java Test.java
,然后出现一系列错误。
错误表明我的所有导入都不存在
Main.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
^
Main.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.Platform;
^
Main.java:5: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
Main.java:6: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
^
Main.java:7: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.DesiredCapabilities;
^
Main.java:8: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.RemoteWebDriver;
^
Main.java:16: error: cannot find symbol
DesiredCapabilities caps = new DesiredCapabilities();
^
symbol: class DesiredCapabilities
location: class Main
Main.java:16: error: cannot find symbol
DesiredCapabilities caps = new DesiredCapabilities();
^
symbol: class DesiredCapabilities
location: class Main
Main.java:25: error: cannot find symbol
WebDriver driver = new RemoteWebDriver(new URL(URL),caps);
^
symbol: class WebDriver
location: class Main
Main.java:25: error: cannot find symbol
WebDriver driver = new RemoteWebDriver(new URL(URL),caps);
^
symbol: class RemoteWebDriver
location: class Main
Main.java:27: error: cannot find symbol
WebElement element = driver.findElement(By.name("q"));
^
symbol: class WebElement
location: class Main
Main.java:27: error: cannot find symbol
WebElement element = driver.findElement(By.name("q"));
^
symbol: variable By
location: class Main
12 errors
我在做什么错?如何获取我的代码以正确找到这些导入?
编辑:我看过其他答案,但它们对我不起作用。我所有的jar文件都位于C:\Users\NROLL97\Documents\jars
。这是我尝试过的示例:
javac -cp "C:\Users\NROLL97\Documents\jars\*.jar:." Main.java
解决方法
对于可能遇到此问题的任何人...
需要这样的东西:
java -cp ".\target\classes;lib\*;" org.testng.TestNG ParallelTestXML.xml
.\target\classes
是类文件(而不是.java文件)的路径,lib\*
是jars
文件夹中我所有lib
的路径。 / p>
现在将找到所有必需的依赖项
,好的 我要向您推荐的第一件事是关于如何编译源代码,而不是编写要与其他任何类名一起编译的每个类名,只需使用* 示例:javac * .java(按Enter键)
此命令将一次编译所有Java源文件,而不是单独编写它们的名称
好的,请解决您的问题 您的编译器找不到硒包或包含所有与硒类相关的类的.jar文件。
下载其中包含硒相关类的.jar文件,并将其保存在保存main.java和Test.java文件的位置
然后尝试对其进行编译
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。