Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

system properties

 
Tushar Kapila
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is for standalone apps and j2ee

i assumed that System.getProperties() also returns properties set by us in the OS variables. especially as i read that on MAC that is the only way to send options to java as program arguments are not supported.

but it seems we must send user properties as -DpropName=value1

even though the batch program starting java can see the OS property we are interested in.

if anyone has mac - is this the case with java on mac too?

shouldn't java pass us all OS properties? it does initialize user.dir , user name etc from windows so why not take all?
 
Rob Spoor
Sheriff
Pie
Posts: 20496
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because these were not regarded as necessary. Since Java 5.0 you can use System.getenv() or System.getenv(String property) for this. Actually you could use the latter before Java 5.0 as well although it was deprecated in Java 1.4.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15208
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tushar Kapila wrote:especially as i read that on MAC that is the only way to send options to java as program arguments are not supported.

Where did you read that? Maybe you didn't understand correctly what was meant? You can pass arguments to a Java program on a Mac when running it from the command prompt just like on Windows, Linux or other operating systems.

Works fine on my Mac:

> javac Example.java
> java Example hello world
args = [hello, world]
 
Tushar Kapila
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mac args -read it in an email from a client ... maybe it was arguments in a short cut to java ?

anyway good to know about getEnv
thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic