System properties

June 4th, 2004

This article about System.getProperty (via Erik)blew me away. I was utterly convinced that System.getProperty() gave me everything I've set in my environment, that I had to try it out. And I was quite baffled to see that the author was right.

However, his proposed solution threw a "java.lang.IllegalArgumentException: Malformed \uxxxx encoding." on my Windows XP machine.

4 Responses to “System properties”

  1. Laszlo Marai Says:
    Well, the javadoc for java.lang.System tells you that you were wrong. It has a depricated method getenv to get the OS environment variables. I just tried it and it throws an Error. The preferred method is to pass the environment variables you need to the java runtime using the -D switch. (And most of the times it's sensible, the only problem I can see is when you don't start your application with a shell script but rather use an indirect way, like launchers, file associations, etc.)
  2. Tom Klaasen Says:
    The javadoc says: "Gets the system property indicated by the specified key." I was just amazed that a "system property" is not the same as an "OS environment variable".
  3. Tom Hawtin Says:
    System.getenv works again in 1.5, and there's also System.setenv.
  4. -marc= Says:
    Odd how people think differently. I would've never expected os env variables to be propagated as system props. In fact I remember digging ant cvs after being intrigued by how their trick DID allow to read those variables (through the same exec hack)

Leave a Reply