wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Permanently setting a System property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Permanently setting a System property" Watch "Permanently setting a System property" New topic
Author

Permanently setting a System property

Yoo-Jin Lee
Ranch Hand

Joined: Nov 01, 2000
Posts: 119
Hi,
I would like to know if you could permanently set a System property. Like user.home or add a new one? I think you can, but I forgot which file to modify...?
Thanks in advance.
Yoo-Jin.
[This message has been edited by Yoo-Jin Lee (edited January 07, 2001).]
Sajan Joseph
Ranch Hand

Joined: Jan 05, 2001
Posts: 40
Originally posted by Yoo-Jin Lee:
Hi,
I would like to know if you could permanently set a System property. Like user.home or add a new one? I think you can, but I forgot which file to modify...?
Thanks in advance.
Yoo-Jin.
[This message has been edited by Yoo-Jin Lee (edited January 07, 2001).]

Hi Lee,
I guess the file you have to modify is System.Properties. You can get the Properties associated with the system using
System.getProperty().
If you want to set any property you can use
System.setProperty()--> added by Java 2.
There are several system properties available like
java.version -- Java Runtime Environment version
java.vendor -- Java Runtime Environment vendor
java.vendor.url -- Java vendor URL
java.home -- Java installation directory
etc.
Refer the Java documentation for further details.
SJ
Yoo-Jin Lee
Ranch Hand

Joined: Nov 01, 2000
Posts: 119
Hi Sajan,
Thanks for your reply,
What I wanted to know though is where the actual file resides. Because System.setProperty(..) is not persistent.
ie.
public class Changer {
public void main(String [] args){
System.setProperty("user.home", "c:\\Temp");
}
}
public class Reader{
public void main(String [] args){
System.getProperty("user.home");
}
}
Invoking Changer then Reader would produce whatever the current directory is ie:
c:\Area51
and not c:\Temp.
I would like to modify the actual file permanently if possible or add my own name/value ie. user.path = c:\temp.
cheers,
Yoo-Jin.
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Yoo-Jin,
When you invoke the JVM, trying adding the -D option.
E.g. java -Duser.home=c:\\temp Reader
-Peter
Yoo-Jin Lee
Ranch Hand

Joined: Nov 01, 2000
Posts: 119
Peter,
Thanks for your reply. I ended up doing that but I wish I could actually see the actual System file.
cheers,
Yoo-Jin.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
First of all, Properties is a java class that is used to hold properties that maybe needed for your program. The basic properties that you are talking about are provided by the operating system. Not all of these can be changed. If you try, you will get a SecutrityException (You can't change the os.name for instance). The basic properties are read from the memory of the computer (basically) you can add additional variables to this by setting environment variables in the operating system you are using. Such as in Win95 you can add to the autoexec.bat the line:
set BARTENDER_NAME=Carl
This line can go in any batch file and BARTENDER_NAME will equal Carl until you reset it.
In your java program If you add the line
System.out.println(System.getProperty("BARTEDER_NAME"));
You'll get Carl as the output.
In the bash shell on Linux or Unix you'd use
BARTENDER_NAME=Carl
export BARTENDER_NAME
You can create your own set of properties for your java program and store them in a file and load them using the Properties load() method.
Hope this helps

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Yoo-Jin Lee
Ranch Hand

Joined: Nov 01, 2000
Posts: 119
Carl,
Thank you so much for your help. That was extremely enlightening. Your the best.
cheers,
Yoo-Jin.
 
wood burning stoves
 
subject: Permanently setting a System property