ziab
asked on
Problem with System.setProperty(key, value)
Instead of "System.getEnv()", which is deprecated since java 1.2, we use the method "System.getProperty(Key ) for the reading of environment- variables.
With the method "System.setProperty(key, value)" we set a selfdefined environment-variable.
When we start another Programm which read the selfdefined environment-variable with the method "System.getProperty(Key )" we get returnvalue "null".
Which Lifetime has a Property set by the "System.setProperty(key, value)" method?
Ziab
With the method "System.setProperty(key, value)" we set a selfdefined environment-variable.
When we start another Programm which read the selfdefined environment-variable with the method "System.getProperty(Key )" we get returnvalue "null".
Which Lifetime has a Property set by the "System.setProperty(key, value)" method?
Ziab
If you wanna make the new defined key available to an other process (second JVM), try to save your properties in the first process and load them in the second one.
Have a look at java.utils.Properties class and something like
....
Properties myProps = System.getProperties();
myProps.put(key,value);
myProps.save("myPropertyFi le");
....
In second program do something like
....
Properties myProps = Properties.load("myPropert yFileName) ;
System.setProperties(myPro ps);
....
Have a look at java.utils.Properties class and something like
....
Properties myProps = System.getProperties();
myProps.put(key,value);
myProps.save("myPropertyFi
....
In second program do something like
....
Properties myProps = Properties.load("myPropert
System.setProperties(myPro
....
I think the only way to change env variables for an "upcomming" program is to change the env array you use in "java.lang.Runtime.exec".
As far as I can remember env. variables are static they are parameters when you start the program up. And can only be changed within a batch/command script.
Pls. correct me if I'm wrong!
As far as I can remember env. variables are static they are parameters when you start the program up. And can only be changed within a batch/command script.
Pls. correct me if I'm wrong!
ASKER
Thanks for the comments,
but we are seaching for a possibility to set, save and hold a selfdefined env-var in the env only with Java.
Ziab
but we are seaching for a possibility to set, save and hold a selfdefined env-var in the env only with Java.
Ziab
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Sankar S.
All this means that the properties will be shared between applications that run on the same instance of a JVM. Programs running on different instaces will not share properties (because the setProperty method does nothing to change any external objects in any way).
I am not 100% sure about this, as I never worked with properties, just looked at the docs and source code for System so if other experts can correct/confirm my answer, please do :-)