0

.I have created a runnable Jar using Eclipse. The IEDriverServer.exe is present in the Jar. I am treating IEDriverServer.exe as a resource for the project.

The below line of code

System.setProperty("webdriver.ie.driver", "C:/Folder1/RunnableJar.jar/IEDriverServer.exe");

throws Driver executable doesn't exist in the following path.

I have put IEDriverServer.exe in the bin folder of the project. I am using the below line of code to get the path of IEDriver that is present in the bin folder.

MainClassName.class.getProtectionDomain().getCodeSource()
                .getLocation().getPath() + "/IEDriverServer.exe";

If I am running the code from Eclipse then the path is the path to the IEDriverServer present in the bin folder. If I am exporting the project as a runnable Jar then the path is as shown below

C:/Folder1/RunnableJar.jar/IEDriverServer.exe

If I am running it from the eclipse it works fine.

It throws the exception if I am running it as jar.

I would like to know the way to set IEDriverServer.exe property from within the Runnable jar.

Code Enthusiastic
  • 2,827
  • 5
  • 25
  • 39

2 Answers2

2

You can't run exe file directly from jar. You can only write a method that would be extract your exe to a temporary folder and then set your System.setProperty to that path value.

You can find some code example there

Community
  • 1
  • 1
QAutomatron
  • 307
  • 3
  • 15
0

It seems there is no way to run exe directly from a Jar on Windows Platform.

As mentioned in one of the answers, the best way is to extract the exe from the jar to a temporary directory and set the property path to that directory.

The following links may help others with the same issue.

Link1

Link2

Link3

Community
  • 1
  • 1
Code Enthusiastic
  • 2,827
  • 5
  • 25
  • 39