I have a problem with implementing automatic chromedriver for Selenium unpacking from .jar file.
Having
ClassLoader classLoader = getClass().getClassLoader();
URL resource = classLoader.getResource("resources/drivers/chromedriver.exe");
File f = new File("Driver");
if (!f.exists()) {
f.mkdirs();
}
File chromeDriver = new File("Driver" + File.separator + "chromedriver.exe");
if (!chromeDriver.exists()) {
try {
chromeDriver.createNewFile();
org.apache.commons.io.FileUtils.copyURLToFile(resource, chromeDriver);
} catch (IOException e) {
e.printStackTrace();
}
}
return chromeDriver.getAbsolutePath();
in one class, that returns the path to the executable driver, which is used in
System.setProperty("webdriver.chrome.driver", the_path);
Printing out path gives me obviously proper path to the driver file, and the file is being created under given directory right. Yet, while running .jar the following problem occures
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
(...)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
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)
but only while triggering the class that's using the driver.
Is there anything to be changed in the code itself or am I missing some crucial things in compilepath or something similiar?
Would appreciate any help!