setting environment variables jre 1.5
I need to set an environment variable in my java application. I have heard that in jre 1.5 you can use System.setenv(). However, I don't see it anywhere. I've read many articles regarding using an external command (exec()) to do this. However, I'd like to not do this if possible. Is there a way or not?
Thanks.
-Jim
There's System.getEnv() to get an env var. There's no setEnv.
Env vars are applicable in a given shell. A program can't alter the environment of the shell that launched it. This isn't specific to Java. Using exec() to set an env var would set it only in the context of the set command itself. It wouldn't be visible anywhere.
You can set system properties for use inside your Java app. If you're trying to set something outside, can you explain more about what you're trying to do and why? In windows you might be able to set a permanent env var by mucking with the registry through exec(), and on unix you could theoretically modify a .profile or whatever file. But those are highly non-portable.
> Hi JIM
>
> I need a help on Remote System Directory Listing and
> Navigation. I had seen a post from you. I need to
> develop a similar kind. Can you please help if you
> have done it.
>
> Thanks in Advance
You should start your own thread for this. You'll have a better chance of getting help.
jverda at 2007-7-16 13:53:20 >
