tek*_*ara 24 java system-properties
如何从我的java程序外部更改user.home系统属性,以便它认为它与D:\ Documents and Settings \%USERNAME%不同?通过环境变量或VM参数?
Chs*_*y76 32
设置VM参数应该有效:
java -Duser.home=<new_location> <your_program> 
这是一个测试用例:
public class test {
  public static void main(String[] args) {
    System.out.println(System.getProperty("user.home"));
  }
}
在Win XP和Linux上使用java 1.5.0_17进行测试
java test
/home/ChssPly76
java -Duser.home=overwritten test
overwritten 
joe*_*ker 19
如果要user.home为所有Java程序设置,可以使用特殊环境变量_JAVA_OPTIONS.
$ export _JAVA_OPTIONS=-Duser.home=/some/new/dir
$ java test
Picked up _JAVA_OPTIONS: -Duser.home=/some/new/dir
/some/new/dir
| 归档时间: | 
 | 
| 查看次数: | 35682 次 | 
| 最近记录: |