Search code examples
mavenenvironment-variablessystem-properties

Maven3 system.property user.home vs environment variable HOME


There seems to be a problem with the system properties in Maven. It seems that system properties don't correspond to the environment variables.

The situation is that I would like to the change the absolute location of the user-specific settings.xml file, as the Maven document says

If you need to create user-specific settings from scratch, it’s easiest to copy the global settings from your Maven installation to your ${user.home}/.m2 directory

which means that the only way to change the absolute location of the user-specific file is to change the user.home property. But it seems that this is not exactly the HOME or HOMEPATH environment variable. In fact, I deleted all the environment variables such as HOME and HOMEPATH, and run mvn using mvn -X just to see the user-specific settings.xml that mvn uses. The result is the following (I am in Windows 7 and I run the command in cmd.exe):

enter image description here

Maven still finds a user.home property, however, I haven't set such a environment variable. To verify this, I then run the set command to see all the environment variables but find nothing about the path d:\Userfiles\xili\ which is used by Maven as the user.home system property. By the way, there is no settings.xml file in this path, because I haven't put any file in this path.

How maven figure out such a path as user.home?


Solution

  • The answer is here!

    http://www.timehat.com/javas-user-home-is-wrong-on-windows/

    In fact, in Windows, the JVM uses the PATH_TO_DESKTOP_FOLDER_AS_SET_IN_THE_REGISTRY as the reference to determine wheres is the user.home.

    user.home is just the parent folder of the above path. That't it, this has nothing to do with the HOME or HOMEPATH enviroment variable.

    In the source code of Maven, there should be some code like System.getProperty('user.home').