Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

env variables

 
Jason Fagerness
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21212
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic