aspose file tools*
The moose likes Beginning Java and the fly likes how to use the environment variables ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to use the environment variables ?" Watch "how to use the environment variables ?" New topic
Author

how to use the environment variables ?

Tom John
Greenhorn

Joined: Apr 15, 2002
Posts: 29
When we use java to develop soft under win2000 , we always set some environment variables to cotroll the application program. For example , we always to set the CLASSPATH . Now I want to know are there any other environment variables specified by JVM ? what are these ? (Can you list these variables , thanks !) And can I define some environment variables by myself ?How can I use these environment variables defined by myself in the java application program ?
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
To compile and run your java programs you don't need to set any other environment variable apart from CLASSPATH.
Earlier versions of Java support System.getenv("env_variable") to retrieve the value of Environment variables. This method is now deprecated.The preferred way to extract system-dependent information is the system properties of the java.lang.System.getProperty. You can define variables in a property file and use getProperty to retrive their values.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
chinese albert
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Tom John
Greenhorn

Joined: Apr 15, 2002
Posts: 29
hi Snigdha Solanki !
thank you for your answer .That make me clear very thing . But I have last questions obscurity.How to get the environment from a propertis files and how to set the environment for the system?

Originally posted by Snigdha Solanki:
To compile and run your java programs you don't need to set any other environment variable apart from CLASSPATH.
Earlier versions of Java support System.getenv("env_variable") to retrieve the value of Environment variables. This method is now deprecated.The preferred way to extract system-dependent information is the system properties of the java.lang.System.getProperty. You can define variables in a property file and use getProperty to retrive their values.
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
See the following code which retrieves the variables from properties file(properties.txt)


On running this program
java Test
Property Name is :John
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

If you want to read a environment variable you can on win32 use this:

on UNIX you can use this:

/Rene
[ July 10, 2002: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
 
jQuery in Action, 2nd edition
 
subject: how to use the environment variables ?