Reputation: 36984
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
Upvotes: 7
Views: 14176
Reputation: 8617
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));
}
}
Upvotes: 3
Reputation: 8657
To list all Java System Properties
Use, Then check if you have an area
property:
Properties props = System.getProperties();
props.list(System.out);
See This example
Upvotes: 0
Reputation: 3968
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
Upvotes: 10