4

In a Windows XP system, is there a way to determine the current value of Java's user.home system property without having to write sample program like this?

i.e. from the command line or control panel or registry, etc.?

Community
  • 1
  • 1
Regex Rookie
  • 10,432
  • 15
  • 54
  • 88
  • 1
    I don't see how this question is related to programming, since you are asking for something specifically unrelated. – Jack Jan 12 '12 at 20:19
  • @Jack Sorry that you feel like that. This is a development issue, just like questions about version control (which are not direct programming) are being asked here all the time. I need this to understand **why** Eclipse on Windows XP is NOT creating the per-user configuration directory. Suggestion for a better place to ask? – Regex Rookie Jan 12 '12 at 20:23
  • 2
    @RegexRookie Then why not ask that? And what's the big deal about creating a program to do that? In any case, should be initialized to the window user's home directory. – Dave Newton Jan 12 '12 at 20:25
  • 1
    @Dave Newton Because that's the only piece of information I need to continue troubleshooting on my own. Also note the links I provided in the question. If you know how to determine that value, you'll be blessed. Note that it **isn't** initialized to Window user's home directory (`%HOME%`). – Regex Rookie Jan 12 '12 at 20:26
  • 2
    How can you determine the _current_ value without running a program? It is up to the JVM to decide, and nothing is guaranteed. – Thorbjørn Ravn Andersen Jan 12 '12 at 20:33
  • @Thorbjørn Ravn Andersen Good question. I thought perhaps there's a java command line option, just like `-D`. But I guess there isn't. Anyway, I just wrote that short program and the results are **very** surprising... – Regex Rookie Jan 12 '12 at 20:38

2 Answers2

5

If you need to find the exact value that will be returned for user.home in a java program when it is run under the same user account you should actually run a java program to obtain the value. There is no guaranteed stable mapping to anything else on Windows for this propery and the mapping that is currently used is wrong and it's not unlikely that it will be changed eventually.

This bug entry describes how user.home actually gets it's value currently and discusses several alternatives that might be more appropriate: http://bugs.sun.com/view_bug.do?bug_id=4787931

x4u
  • 13,877
  • 6
  • 48
  • 58
  • 1
    This information is eye opening. I just found out that the user.home value in my system is `%USERPROFILE%` -- contrary to the intuitive `%HOME%`, but identical to `%HOMEDRIVE%\%HOMEPATH%`. Accepting +1. – Regex Rookie Jan 12 '12 at 20:54
  • 1
    @RegexRookie (Which is what Peter said.) – Dave Newton Jan 13 '12 at 01:42
2

To find the user's home directory without running a Java program you can ...

Under windows you need to look at %HOMEDRIVE% and %HOMEPATH%

Under Linux you can use $HOME

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Thank you very much! The problem is that running `eclipse -initialize` doesn't create the `.eclipse` configuration directory in `%HOME%` as described [here](http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/multi_user_installs.html). So, I am suspecting that Java has some different value of its own... I guess I will have to write this throw away program to find out. :) – Regex Rookie Jan 12 '12 at 20:32
  • If you can start Eclipse then you can see all the system properties. – Thorbjørn Ravn Andersen Jan 12 '12 at 20:35
  • `System.getProperty("user.home")` does *not* return the value of the concatenation of `%HOMEDRIVE%` and `%HOMEPATH%` according to the bug report mentioned int x4u's answer. Instead Java looks at the registry to determine the user's desktop folder and strips the `Desktop` off of it, which likely resamples `%USERPROFILE%`. – Micha Wiedenmann Jul 22 '13 at 14:03