Processing
 

How can I include ChromeDriver in a JAR?

08/02/2014 18:37#1

DaniChan

Member

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

I'm writing a web-automation program and so far, it works fine using Selenium's FirefoxDriver. However, I want to make it use Chrome if Firefox is not installed. I downloaded the ChromeDriver, put it inside a folder in my Eclipse project, and ran it. After I added System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe"); it worked fine. However, when I try to export it (using Eclipse's standard Export). It crashes, I believe because it can't find the ChromeDriver (I think this because exporting it with FirefoxDriver works fine).

I have tried changing the .JAR to a .ZIP in order to look inside, and I see that the driver folder was stripped away, simply putting chromedriver.exe inside the top-level JAR. I tried changing the property to System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); but still crashes.

Does anyone know why the exported JAR is unable to find chromeDriver, despite the fact that I have verified that it is in the JAR?

Thanks, Daniel

09/02/2014 07:48Top#2

Ittiel

Member

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

It's in the Jar but cannot be executed (same as trying to run an .exe from a zip file), you have to extract it before running it

09/02/2014 19:50Top#3

Sighil

Member

Joined at: 11 months ago

Post: 4

Thank: 0

Thanked: 0

Export your code as jar without the chromedriver. Create a folder ChromeDriver. Place your chromedriver.exe in this folder. Place ChromeDriver folder along with your jar.

Also dont forget to set the System property in the code to

System.setProperty("webdriver.chrome.driver", "ChromeDriver/chromedriver.exe");  

Please let me know if this works for you.

10/08/2016 07:29Top#4

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

you have to extract it before running it. Copy Your driver under src/resources/drivers/chromedriver.exe

Now whenever you run this code , it will Create a new Folder "Driver" where ever you put your Runnable jar and copy your driver, which you can access.

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()) {                     chromeDriver.createNewFile();                     org.apache.commons.io.FileUtils.copyURLToFile(resource, chromeDriver);                 }                 System.setProperty("webdriver.chrome.driver", chromeDriver.getAbsolutePath());                 driver = new ChromeDriver(); 
Similar articles

Chrome, THREE.js: Cross-origin image load denied

5 years ago - Reply: 5 - Views: 271

Prevent Google Chrome Log XMLHttpRequest

3 years ago - Reply: 5 - Views: 277

How can I include ChromeDriver in a JAR?

3 years ago - Reply: 3 - Views: 83

Chrome geolocation not working on any site

3 years ago - Reply: 1 - Views: 49

wrong borders' width in android browser

3 years ago - Reply: 4 - Views: 207

Uncaught SyntaxError: Unexpected token < On Chrome

3 years ago - Reply: 10 - Views: 472

Flashdata not getting cleared in Codeigniter

4 years ago - Reply: 5 - Views: 58

Illegal access Javascript error in Chrome

3 years ago - Reply: 1 - Views: 53

ng-repeat not updating in Chrome

3 years ago - Reply: 1 - Views: 82

Applying border to a checkbox in Chrome

4 years ago - Reply: 2 - Views: 119

open browser plugin using access vba

3 years ago - Reply: 1 - Views: 26

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re