Change user.home system property

tekumara picture tekumara · Oct 1, 2009 · Viewed 39.8k times · Source

How do I change the user.home system property from outside my java program, so that it thinks it's a different directory from D:\Documents and Settings\%USERNAME%? Via environment variables, or VM arguments?

Answer

ChssPly76 picture ChssPly76 · Oct 1, 2009

Setting VM argument should work:

java -Duser.home=<new_location> <your_program> 

Here's a test case:

public class test {
  public static void main(String[] args) {
    System.out.println(System.getProperty("user.home"));
  }
}

Tested with java 1.5.0_17 on Win XP and Linux

java test
/home/ChssPly76

java -Duser.home=overwritten test
overwritten