File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Creating an environment variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating an environment variable" Watch "Creating an environment variable" New topic

Creating an environment variable

Pete Dawn

Joined: Sep 28, 2006
Posts: 17
guys and gals,

i am trying to create some environment variables from within my java app.

now i have two probs,
1. how should i create a environment variable from within my app.
2. how should i edit the environment variable value.

now what i have done is, i have created the environment variable manually from withing My Computer and then tried to edit it. i am able to retreive the value and even edit it but surprisingly when i go back to my computer to check the new value, its still the old value.

Properties p = ReadEnv.getEnvVars();
String varLoc = p.getProperty(TEST_VAR);

so my question is how can i edit it in such a way that its reflected in my computer too.

and second question, how can i create an environment variable and even delete it if needed.

Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Hi, Pete.

I think the best way (if not the only) is to use a java.lang.ProcessBuilder.

For instance, I just did an example.bat file that contains:

Since the environment variable MY_NAME is not defined, I will have to define it before calling the example.bat.

The way to do it is this:

You will see how the batch file uses the variable that you defined.

Does this help you somehow?
I agree. Here's the link:
subject: Creating an environment variable
It's not a secret anymore!