I have this system variable
this code:
System.out.println(System.getProperty("area"));
returns null.
Could I get acces to system variables from java code through System.getProperty method ?
P.S
This is not a system variable but an environment variable. You can access these variables by using System.getenv()
.
System.getProperty()
is used to return any variables set while starting the program. Example:
# java -Dmyproperty=myvalue MyProgram
System#getProperty
gets you the system properties.
You can access the environment variables Map through System#getenv
System.out.println(System.getenv("area"));
Should get you your results.
EDIT:
Try and run the following code and check if your required variable appears in the console or the behavior is incosistent for other defined variables:
public static void main(String[] args) {
Set<String> envSet = System.getenv().keySet();
for (String env : envSet) {
System.out.println("Env Variable : " + env + " has value : "
+ System.getenv(env));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With