I am trying to read environment variables in Java using
System.getProperty(). I run java as
set myvar="XYZ"
java -Dmyprop="%myvar%"
and if I run following code from command line it works:
public class ABC {
public static void main(String[] args) {
System.out.println(System.getProperty("myprop"));
}
}
However, if I run this through Eclipse then it prints "%myvar%"
instead of "XYZ".
Any solution?
--
Mahesh Soundalgekar.
e-mail: soundalgekar@yahoo.co.uk
John Keyes - 23 Sep 2004 18:09 GMT
Mahesh,
Do you want to run an application in Eclipse and get it to pick up the
value of an environment variable you have set? If this is the case
then you are out of luck. When you launch an application from Eclipse
a new JVM is created, therefore even if you do pass properties to the
eclipse launcher (-vmargs -Dmyprop="%myprop%") they will not be visible
to the new JVM.
If you just want to test system properties you can do this from the
"Run..." dialog. There is an "Arguments" tab which allows you to
specify program and VM arguments. You can add your -Dmyprop="xxx"
here. You will have to supply the value yourself, as I mentioned
earlier you cannot reference the system environment.