aspose file tools*
The moose likes Java in General and the fly likes env variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "env variables" Watch "env variables" New topic
Author

env variables

Jason Fagerness
Greenhorn

Joined: May 11, 2006
Posts: 3
I was trying to figure out how to access an environment variable from inside a java program. It looks like most examples/references use the System.getenv(String) method, but it has been deprecated. Does anyone know of an alternative?

Thanks in advance,
Jason
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18996
    
  40

Originally posted by Jason Fagerness:
I was trying to figure out how to access an environment variable from inside a java program. It looks like most examples/references use the System.getenv(String) method, but it has been deprecated. Does anyone know of an alternative?


IMHO, the reasoning for the deprecation of the getenv() method was just silly. It was deprecated because not all OSes have environment variables -- hence, it is not guaranteed to work in all cases.

Anyway, the method has been undeprecated (is there such a word?), as of Java 5.0. Prior to Java 5.0, it works -- it always worked, provided that you are using an OS that supported environment variables.


The JavaDoc recommends that you use properties instead of environment variables. See the JavaDoc (prior to Java 5) for more detail.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: env variables