Last active
July 1, 2021 20:59
-
-
Save vcabral19/d05234ea35541e78a252a68f9cab86d6 to your computer and use it in GitHub Desktop.
playing with variables in java
This file contains 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
package com.myproject; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.Properties; | |
public class EnvVarTest { | |
public final Properties properties; | |
public EnvVarTest(){ | |
this.properties = new Properties(); | |
String propertiesFileName = "config.properties"; | |
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFileName); | |
try{ | |
this.properties.load(inputStream); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public String getEnvVarOrProperty(String envVarName){ | |
String systemEnvVar = System.getenv(envVarName); | |
if (systemEnvVar == null){ | |
systemEnvVar = properties.getProperty(envVarName); | |
} | |
return systemEnvVar; | |
} | |
public static void main(String[] args){ | |
String eventsSourcePath; | |
String processedRegisteredEventsPath; | |
String processedAppLoadedEventsPath; | |
String sparkMasterConfig; | |
EnvVarTest envVarTest = new EnvVarTest(); | |
eventsSourcePath = envVarTest.getEnvVarOrProperty("EVENTS_SOURCE_PATH"); | |
processedRegisteredEventsPath = envVarTest.getEnvVarOrProperty("PROCESSED_REGISTERED_EVENTS_PATH"); | |
processedAppLoadedEventsPath = envVarTest.getEnvVarOrProperty("PROCESSED_APPLOADED_EVENTS_PATH"); | |
sparkMasterConfig = envVarTest.getEnvVarOrProperty("SPARK_MASTER"); | |
System.out.println("EVENTS_SOURCE_PATH -> " + eventsSourcePath); | |
System.out.println("PROCESSED_REGISTERED_EVENTS_PATH -> " + processedRegisteredEventsPath); | |
System.out.println("PROCESSED_APPLOADED_EVENTS_PATH -> " + processedAppLoadedEventsPath); | |
System.out.println("SPARK_MASTER -> " + sparkMasterConfig); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Protip: config.properties file should be in the "resources" folder of the project!