• Post Reply Bookmark Topic Watch Topic
  • New Topic

Environment Variable Question  RSS feed

 
Mike London
Ranch Hand
Posts: 1505
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I noticed that some JVM environment variables are available using this syntax:

System.getProperty("var.name"),

yet they do not show up in using this syntax: Map<String, String> env = System.getenv(); (that is, the property is not in the returned Map object.) I read that the "getEnv()" is deprecated, but I don't see another way to get the entire list of environment variables in a list.

So, is there a way to get a complete list of environment variables or do you just need to "know" the one(s) you want and then use the .getProperty("...") syntax?

Appreciate any replies in advance.

- m
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to clarify to yourself whether you want a list of environment variables, or a list of system properties. They aren't the same thing. The environment variables are a copy of the operating system's environment variables, whereas the system properties are properties set up by the JVM to control various Java features.

If you want all of the system properties, then "System.getProperties()" will return you a Properties object which you can look at.
 
Mike London
Ranch Hand
Posts: 1505
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You need to clarify to yourself whether you want a list of environment variables, or a list of system properties. They aren't the same thing. The environment variables are a copy of the operating system's environment variables, whereas the system properties are properties set up by the JVM to control various Java features.

If you want all of the system properties, then "System.getProperties()" will return you a Properties object which you can look at.


Yikes, yes I should have known that!

Thanks very much for your kind reply.

- m
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this:-orThey both do the same thing.
 
Mike London
Ranch Hand
Posts: 1505
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Try something like this:-orThey both do the same thing.




Thanks very much. Great info.

Appreciate your reply.

- mike
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome I had those little classes knocking around in some folder or other, so simply had to copy and paste them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!