displayName
displayName

Reputation: 215

How to get relative path of an exe in Java

I have a config class that references a chromedriver.exe file via a String path like so

public static final String CHROMEDRIVER_DIRECTORY = "C:\\Users\\asdf\\Desktop\\Testing\\drivers\\chromedriver.exe";

That code is located in the src folder while the chromedriver.exe is located in a separate drivers folder. The project layout looks something like this.

Testing

  1. src -> constants package -> config
  2. drivers -> chromedriver.exe

How can I edit the string so that it can find the chromedriver without having to type the absolute path? Thanks

Upvotes: 0

Views: 274

Answers (2)

Indrajeet
Indrajeet

Reputation: 66

Keep your chromedriver.exe in one folder in your current project directory(say win). Then use

System.getProperty("user.dir") + File.separator + "win" + File.separator + "chromedriver.exe"

Upvotes: 0

Atahan Atay
Atahan Atay

Reputation: 363

Try "drivers\\chromedriver.exe".

Upvotes: 1

Related Questions