Article View: borland.public.jbuilder.java.language
Article #14466Re: environment variables from within Java
From: Kevin D
Date: Wed, 01 Sep 1999 00:00
Date: Wed, 01 Sep 1999 00:00
71 lines
2981 bytes
2981 bytes
OK I think I am beginning to see the light.
I have got the list of system properties which include "user.dir",
"user.home & "user.name".
So far so good. And they are easy to get at as follows:
startProperties = System.getProperties();
System.out.println(startProperties.getProperty("user.name"));
System.out.println(startProperties.getProperty("user.home"));
Now can I add to the list of system properties.
I thought that if I ran the following:
java -DSystem.userapp_prefs="\\myserver\data\users"
I could use this code to get the value of a new system property
"userapp_prefs".
startProperties = System.getProperties();
System.out.println(startProperties.getProperty("user.name"));
System.out.println(startProperties.getProperty("user.home"));
System.out.println(startProperties.getProperty("userapp_prefs","NOT
SET" ));
This does not seem to work.
The following does work. Using "myprefs".
java -Dmypref.userapp_prefs="\\myserver\data\users"
startProperties = System.getProperties();
System.out.println(startProperties.getProperty("user.name"));
System.out.println(startProperties.getProperty("user.home"));
System.out.println(System.getProperty("mypref.userapp_prefs","NOT
SET" ));
Any thoughts.
Many Thanks
Kevin
Paul Furbacher [TeamB] wrote in message
<37CC4EC7.408B2B2A@bilbo.bio.purdue.edu>...
>Kevin D wrote:
>
>> Is it possible to access the environment variables from within Java?
>> Win NT, Win 95 or Unix
>
>It depends. See the JavaDocs for the System class. There are
>some which are obtainable via System.getProperty(...).
>However, those which you have created are not available.
>
>> If not, is the -D runtime parameter the work-around?
>
>Yes, you could do this. In fact, someone just wrote about doing
>this last week. The problem was that it works from the command
>line, but not from within the IDE (an inconsistency which is puzzling).
>So, if you had an environment setting called "JavaHome", you could
>write the command line:
>
> > set JavaHome=c:\jdk1.1.8
> > java -DjavaHome=%JavaHome% ...
>
>but if you set the -D parameter in the Run | Parameters... dialog
>it would yield "%JavaHome%" and not "c:\jdk1.1.8". Quite
>unfortunate. You may choose to file a bug report on this
>novel feature of the IDE (note that I didn't call it a bug).
>
>
>Paul Furbacher (TeamB)
Technical Details
Message-ID:
<7qjj86$cvu3@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7qhc70$aho9@forums.borland.com> <37CC4EC7.408B2B2A@bilbo.bio.purdue.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1698c67948d2aa23 X-Google-Attributes: gidf74b3,public From: "Kevin D" <kevind@saccapital.com> Subject: Re: environment variables from within Java Date: 1999/09/01 Message-ID: <7qjj86$cvu3@forums.borland.com> X-Deja-AN: 519789740 References: <7qhc70$aho9@forums.borland.com> <37CC4EC7.408B2B2A@bilbo.bio.purdue.edu> Organization: Another Netscape Collabra Server User X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: borland.public.jbuilder.java.language