aspose file tools*
The moose likes Java in General and the fly likes Enviroment Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enviroment Variables" Watch "Enviroment Variables" New topic
Author

Enviroment Variables

Rob Bass
Ranch Hand

Joined: Aug 28, 2001
Posts: 67
Since SUN has deprecated getenv(), does anyone know how to retrieve a user set enviroment variable?
Thanks,
Rob
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
JDK does not provide a way to get environment variables, because they are not a concept common to all platforms. Instead, it provides java.util.Properties . One way to get environment variables into your Java program is to set Java property values to be equal to the environment variable values on the java command line; use the syntax for your platform. For example: -
<code>
java -DmyProp=$MY_PROP myClass
java -DmyProp=%MY_PROP% myClass
</code>
There are standard Java properties for some things you may want to get, such as working directory, home directory, OS name etc. See System.getProperties().
Alternatively, if you really must access actual environment variables, you can make a teeny C program to get their values, and call this via JNI. I suspect that a search on the Web will probably reveal several "how to" documents on this subject, as it must be quite a common requirement.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Just saw a JDC Tech Tip on this one
ACCESSING THE ENVIRONMENT FROM JAVA APPLICATIONS
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enviroment Variables