1

I am wondeirng how to print out all the system variables. I would like to know if I can enumerate them all.

user705414
  • 20,472
  • 39
  • 112
  • 155

4 Answers4

5

Do you mean like?

System.getProperties().list(System.out);

or

for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) 
    System.out.println(entry);
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
3

System.getProperties() is what you're after - you can then enumerate through those. You can call the values() or propertyNames() methods on the returned property object depending on whether it's the names or the values that you're after (or of course the entrySet() for both.)

Alternatively you can use the list() method directly if all you want to do is print them out somewhere.

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
1

There are 3 places where you can find a kind of system or environment variables.

  1. System.getProperties()
  2. System.getenv()
  3. various properties of RuntimeMBean that can be accessible using ManagementFactory.getRuntimeMXBean()
AlexR
  • 114,158
  • 16
  • 130
  • 208
0

You can use SqlTool to list all or a specified Java system property on the command line. No Java SDK or coding required.

Download the SqlTool jar file by clicking on the Download "jar" link on this Maven repository page.

You can then dump all Java system properties with:

java -jar path/to/sqltool-VERSION.jar --sql "*listsysprops"

To list a specific system property value, just add it after 'listsysprops', like

java -jar path/to/sqltool-VERSION.jar --sql "*listsysprops user.home"
Blaine
  • 1,577
  • 2
  • 17
  • 15