Last active
November 20, 2018 15:38
-
-
Save sauceaaron/fce0b87fcc7b833845bf84671fa40e2f to your computer and use it in GitHub Desktop.
Load browser configuration from properties file, environment variable, command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.Properties; | |
| public class BrowserConfig | |
| { | |
| public String getBrowserPath() | |
| { | |
| String browserPath = "/Applications/Firefox.app/Contents/MacOS/firefox"; // default | |
| String fromPropertiesFile = loadPropertiesFile("browser.properties").getProperty("browserPath"); | |
| String fromEnvironmentVariable = System.getenv("browserPath"); | |
| String fromSystemProperty = System.getProperty("browserPath"); | |
| if (fromPropertiesFile != null) { browserPath = fromPropertiesFile; } | |
| if (fromEnvironmentVariable != null) { browserPath = fromEnvironmentVariable; } | |
| if (fromSystemProperty != null) { browserPath = fromSystemProperty; } | |
| return browserPath; | |
| } | |
| public Properties loadPropertiesFile(String filename) | |
| { | |
| ClassLoader loader = Thread.currentThread().getContextClassLoader(); | |
| Properties properties = new Properties(); | |
| try | |
| { | |
| InputStream resourceStream = loader.getResourceAsStream(filename); | |
| properties.load(resourceStream); | |
| } | |
| catch (IOException e) | |
| { | |
| e.printStackTrace(); | |
| } | |
| return properties; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment