0

Below is my code which works perfect in Eclipse Java Project

    String IEPath = "src/IEDriverServer.exe";
    File file = new File(IEPath);
    System.setProperty("webdriver.ie.driver",file.getPath());
    WebDriver driver = new InternetExplorerDriver();

If I export the same code to a runnable JAR file and double click it or if I run it from command prompt gives below exception

    The driver ececutable does not exist C:\Backup\New folder\src\IEDriverServer.exe

I have copied IE exe inside my Java Project and have exported the Java Project including the IE exe. When I run the JAR, it is failing to pick the IE exe path. Please help! TIA!

Shawn
  • 4,064
  • 2
  • 11
  • 23
  • Objects in a jar are not files and you can't use `File` to access them. – greg-449 Feb 22 '17 at 18:29
  • @greg-449 Many thanks for your comment. Could you please help me what code I should right so that it reads my IE exe path. TIA! – Shawn Feb 22 '17 at 18:32
  • @ShawnDsouza use class.getResource("path to exe relative to this class") – rvit34 Feb 22 '17 at 18:46
  • I got answer to my question on this link http://stackoverflow.com/questions/20389255/reading-a-resource-file-from-within-jar?noredirect=1&lq=1 – Shawn Mar 10 '17 at 14:09

1 Answers1

0

You have two options here:

  1. Read the resource inside the jar. See more info here.

  2. Use WebDriverManagerto automate the management of IEDriverServer.exe.

For alternative 2, simply import the WebDriverManager library in your project and change your code:

String IEPath = "src/IEDriverServer.exe";
File file = new File(IEPath);
System.setProperty("webdriver.ie.driver",file.getPath());

... by:

InternetExplorerDriverManager.getInstance().setup();
Community
  • 1
  • 1
Boni García
  • 4,618
  • 5
  • 28
  • 44
  • Thanks all for your precious comments. – Shawn Feb 27 '17 at 19:23
  • I got answer to my question on this link http://stackoverflow.com/questions/28615441/how-to-access-resource-files-from-jar-file?noredirect=1&lq=1 – Shawn Feb 27 '17 at 19:23