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

Until Java 8 where this is fixed, the solution is to 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/


It looks to me as if - for whatever reasons - %USERPROFILE% has not been set to a value. What do you get if you type echo %USERPROFILE% on the command shell?

Maybe it's not a OS feature but a configuration issue. On my machine (Vista) %USERPROFILE% resolves to my home directory and it's the same for the Java property user.home

Edit

Here's an Vista/Windows7 issue with USERPROFILE and user.home: bug. May not solve your problem might give you an idea..


The majority of the registry keys located at:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

began with %userprofile%. I updated all of the registry keys that began with %userprofile% to begin with C:\Users\myusername. I verified on Windows XP that the paths are in fact hard coded and that %userprofile% is not used. The IT guys mentioned that the registry keys defaulted to use %userprofile% due to a default profile being used within Windows 7. The JVM expects the Desktop path to be hard coded. It will not evaluate environment variables.

You can update the registry keys one by one or you can export the folder out and change the keys. Here is how you can export and import the registry keys:

  1. Go to Start > Run.
  2. Type regedit. This opens the registry editor.
  3. Browse to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders.
  4. Right click on Shell Folders and choose Export.
  5. Select the Desktop as the destination and enter Shell Folders for the file name and save the file.
  6. Open the file in a text editor and replace %userprofile% with C:\\Users\\yourusername. Save and close the file.
  7. Go back to the registry editor window and select File > Import from the main menu.
  8. Select Shell Folders.reg and click Open.
  9. Close the registry editor and delete the Shell Folders.reg file off of the desktop.

This is due to an long outstanding bug in Java: http://bugs.sun.com/view_bug.do?bug_id=4787931