This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes getProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getProperty" Watch "getProperty" New topic
Author

getProperty

Bill Norton
Greenhorn

Joined: Mar 29, 2001
Posts: 27
I understand getenv has been deprecated. ok
How do I get these values?
For instance and I'm working on Linux here...
setenv MYVAR 123456
Now, if I do a
System.out.println("MYVAR");
I get a Null value, what am I doing wrong?
I have also tried other variable with the same result.
The only values that I can get are pre-defined values(java.version, etc..)
Thanks for any help.
Bill Norton
Julia Reynolds
Ranch Hand

Joined: May 31, 2001
Posts: 123
Check out this thread on the Java.sun.com:
http://forums.java.sun.com/thread.jsp?forum=31&thread=56739
Julia
Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
You can set the operating system all you want, and Java is not going to know about it. The Properties that java knows how to get are listed in the API under System.getProperties. Try:
System.out.print(System.getProperties());
If you want to store more properties that then you have to create new properties in java, and load them yourself. Some applications have a .properties file to do this. At execution they read the .properties file and add those to the ones that java already knows about.
Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
Actually julia's solution might be even more helpful...try setting the environment variable MYVAR and then running the application like this java -DMYVAR=$MYVAR (Application name)
Bill Norton
Greenhorn

Joined: Mar 29, 2001
Posts: 27
Thank you for your suggestions and the thread on Sun's page.
I have to admit though this is pretty disgusting. I not a Java guru but Sun really seemed to drop the ball on this one. How can you deprecate a function and give no alternative way? Especially something as important as pulling in environment variables!!!
If anyone could explain this to me I would be thankful.
Bill Norton
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getProperty
 
Similar Threads
database value in backingBean
Variable declaration inside loops - what happens?
Shorten conditions
PL/SQL compilation error
Passing variables