如何从具有相同结构的不同jar中解析我的类
Note : Though the jars in question contains the word selenium but the question here have no direct relation with selenium
几天前,PhantomJSDriver与selenium-server-standalone-v.v.v.jar捆绑在一起发布.所以我的班级工作正常:
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class A_PhantomJS
{
public static void main(String[] args)
{
File path=new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
WebDriver driver= new PhantomJSDriver();
driver.manage().window().maximize();
driver.get("https://www.google.co.in");
}
}
现在,selenium-server-standalone-v.v.v.jar不会将jar包装为PhantomJSDriver依赖项.
所以我下载了jar phantomjsdriver-1.1.0.jar并将其作为外部jar添加到我的项目中.
您可以看到phantomjsdriver-1.1.0.jar的结构与之前与selenium-server-standalone-v.v.v.jar捆绑时的结构类似.
现在,虽然我的班级通过以下方式解决:
import org.openqa.selenium.phantomjs.PhantomJSDriver;
但我面临java.lang.NoClassDefFoundError的运行时异常,如下所示:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
at demo.A_PhantomJS.main(A_PhantomJS.java:15)
Caused by: java.lang.classNotFoundException: org.openqa.selenium.browserlaunchers.Proxies
at java.net.urlclassloader.findClass(UnkNown Source)
at java.lang.classLoader.loadClass(UnkNown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(UnkNown Source)
at java.lang.classLoader.loadClass(UnkNown Source)
... 4 more
第15行是:
WebDriver driver= new PhantomJSDriver();
根据错误,我搜索了phantomjsdriver-1.1.0.jar中的org.openqa.selenium.browserlaunchers.Proxies无法找到任何线索.
有人可以帮帮我吗?
解决方法:
这个jar包含org.openqa.selenium.browserlaunchers.Proxies,尝试将它添加到你的类路径中:
如果您错过了其他课程,可以使用Maven Central Repository:https://search.maven.org/#advancedsearch%7Cgav上的高级搜索按类名进行搜索
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。