Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Windows 7, how does Java JVM set "user.home" System property?

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

like image 206
kevinarpe Avatar asked Jun 03 '13 04:06

kevinarpe


People also ask

How do I set Java system properties in Windows?

System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime using System. setProperty(String key, String value) or via the various System. getProperties().

What is JVM system property?

System properties contain information to configure the JVM and its environment. Some system properties are particularly relevant for JVMs in a CICS® environment. Specify JVM system properties in the JVM profile.

How do I see Java properties in Windows?

In Java, you can use System. getProperties() to get all the system properties.


2 Answers

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

like image 170
kevinarpe Avatar answered Sep 27 '22 21:09

kevinarpe


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/

like image 36
Luka Bradeško Avatar answered Sep 27 '22 20:09

Luka Bradeško