How to get an operating system in Java
I know there is such a question on SO, but I couldn't find it. So ask again ...
I need to set up properties for my program, but I need to make it OS indipendent - working on both Windows XP and Linux (unknown distribution, unknown version)
Specifically - I need to set up a system where the binary can be found chromedriver
. I need something like this pseudocode:
if (getOs() == Windows){
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
} else{
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver");
}
Now I need the part to get the OS. Thanks for the help.
+3
source to share
2 answers
You can use the utility class I wrote, you just need to copy the following class to your project
https://github.com/aurbroszniowski/os-platform-finder/blob/master/src/main/java/org/jsoftbiz/utils /OS.java
Then execute:
import org.jsoftbiz.utils.OS; OS myOS = OS.getOs (); myOS.getPlatformName () myOS.getName () myOS.getVersion () myOS.getArch ()
0
source to share