Environment Variables in Squirrel
Environment variables are a universal mechanism for conveying configuration information to Unix programs. Let’s look at how to set, get, and list environment variables in Java.
Running the program shows that we don’t pick up the value for FOO
that we set in the program using System.setProperty()
, because System.getenv()
only retrieves environment variables set outside the Java program. BAR
is null as it’s not set.
The list of keys in the environment will depend on your particular machine.
If we set BAR
in the environment first, the running program picks that value up.
Note that in Java, unlike in some other languages, you can’t modify the environment variables of the current process. The System.setProperty()
method sets a system property, which is different from an environment variable. To set an environment variable that’s visible to the Java program, you need to set it before running the Java program, as shown in the last example.