16

I am using JRE 1.7 and I discovered the user.home System property is very unusual. How does the JVM set this value?

kevinarpe
  • 20,319
  • 26
  • 127
  • 154

2 Answers2

24

This Java bug explains how: http://bugs.sun.com/view_bug.do?bug_id=4787931

System property user.home is set by:

  1. Read the registry value for key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop
  2. Take the parent path of this value, but do not resolve environment variables.

Example: %userprofile%\Desktop => %userprofile% (unresolved environment variable)

This issue should be fixed in Java 8.

Related Ref: Java user.home is being set to %userprofile% and not being resolved

Community
  • 1
  • 1
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
8

In windows it gets it like stated in the accepted answer, and is dependent of the Desktop folder location.

There is workaround if you want to change your default Desktop folder location, and still want to have user.home in the same folder:

add this into the environment variables:
_JAVA_OPTIONS:-Duser.home=%HOMEDRIVE%%HOMEPATH%

or in command line:
set _JAVA_OPTIONS=-Duser.home=%HOMEDRIVE%%HOMEPATH%

I saw the solution in the comments of this page: http://www.timehat.com/javas-user-home-is-wrong-on-windows/

Luka Bradeško
  • 542
  • 7
  • 16
  • Nice suggestion! I never know about this env var. I learned more about it here: https://stackoverflow.com/questions/17781405/information-about-java-options – kevinarpe Jan 07 '21 at 09:11