cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
james_decosta
Level 9

please verify why this code does not work

hi,
i got this custom code from the samples but it does not seem to work as the system environment variables are not getting refreshed.

I used system.out.println after setting environment variable and using refresh environment action but it simply does not output anything.
It is not setting the environment variable.
i wrote the following code but it prints null

String mystr=System.getEnv("MY_HOME");
System.out.println(mystr);
String anotherPlace=mystr+"\\My.properties";
File myFile=new File(anotherPlace);

I use it on windows xp
where am i wrong and the stack trace of stdout.log is


ExtractToFile: target = C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\I1202120738\Windows\refresh.dll
ExtractToFile: extractWhatURL = jar:file:/C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/I1202120738/InstallerData/Execute.zip!/refresh.dll
Labels (1)
0 Kudos
(8) Replies
pv7721
Level 20

On what platform does this happen?
0 Kudos
purcellk24
Level 7

What gets printed out when you run this code? Adding other debug lines may help tell you exactly where you are in the code.
Try
System.out.println("MyStr = " + mystr);
Another thing, you don't need to create the variable anotherPlace. Instead, just use File myFile = new File(mystr, "My.properties");
0 Kudos
james_decosta
Level 9

hi,
i used it on windows xp platform.
james.
0 Kudos
james_decosta
Level 9

hi
the answer i got here is
MYSTR=null
What shall i do now???????????????/////
0 Kudos
james_decosta
Level 9

hi,
i added execute custom code after setting the environment varaibles and then gave refreshenvironment.jar in the custom code archive path and then i gave
RefreshEnvironment in the class.
I dont know where i am going wrong but it simply does not refresh the system environment variables for use without restarting the system
0 Kudos
james_decosta
Level 9

hi,
i have a issue out here in that the refresh environment class does not work
as when i used this line say,i got null.


String letMeSee=System.getEnv("XXX_HOME");
System.out.println("will it be printed"+letMeSee);

i got output as this:
"will it be printed"null
It means the environment variables are not getting refreshed.
0 Kudos
purcellk24
Level 7

Ok here goes....
When you are making a System.getenv() call, you are getting settings for the current Virtual Machine. Just because you changed the "environment" at the system level, doesn't mean the currently running JVM environment has been updated. Just like if you opened a cmd window. That window has a particular environment. That environment doesn't get automatically updated because you changed it at the "system" level. It only gets updated when you explicitly set it or you open a new cmd window.

There are 2 ways aound this.
1. Use a System.setProperty(key, value) call.
or 2. You said that in IA, you were setting the variable. Why not just use that variable?
0 Kudos
james_decosta
Level 9

hi,
i set system environment variable JAVA_HOME if jdk is not there and i use it to start script file.What to do when it refers to the new JDK.
When i set the system environment variable in installer will it get refreshed.
Say i set JAVA_HOME will it get refreshed,I am not sure .I did not find it happening.
james.
0 Kudos