Java user.home is being set to %userprofile% and not being resolved
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:
- Go to Start > Run.
- Type
regedit
. This opens the registry editor. - Browse to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
. - Right click on
Shell Folders
and choose Export. - Select the Desktop as the destination and enter
Shell Folders
for the file name and save the file. - Open the file in a text editor and replace
%userprofile%
withC:\\Users\\yourusername
. Save and close the file. - Go back to the registry editor window and select File > Import from the main menu.
- Select
Shell Folders.reg
and click Open. - Close the registry editor and delete the
Shell Folders.reg
file off of the desktop.
How is the value of ${user.home} initialized?
The variable is defined by the JVM, not by Maven, and it's taken from the system settings. If the value is wrong, then the system isn't properly configured.
Maybe this answer can help you.
maven ${user.home} not being resolved correctly
This might be a bug in maven. I've bookmarked this workaround some time ago:
I found a handy way to reference the
Java system property${user.home}
within a Maven build that supports
Windows' ridiculous path name to
home/profile directories:c:\Documents and Settings\foobar.
The problem is, when using Maven, this
parameterized property doesn't get
passed through as one property value,
but as three, because somewhere in the
build Maven chokes on the spaces or
back-slashes and interprets it as
either three arguments:"c:\Documents", "and", "Settings\foobar"
or treats the windows back-slash as an
escape character and removes them so
my parameterized user.home becomes:"c:Documents and Settingsfoobar"
[...]
However, on Windows XP, unless I set
the user.home on the build path every
time, the back-slash escaping or space
issues cause the files to not be
found.To fix it, add this profile to the
$M2_HOME/conf/settings.xml
file:<profile>
<id>laptop-xp</id>
<properties>
<user.home>C:/Documents and Settings/${user.name}</user.home>
</properties>
</profile>
Then add an appropriate entry to the
activeProfiles:<activeProfile>laptop-xp</activeProfile>
Now every user will be able to use the
user.home
property to reference
their home path correctly on the
Windows box.
Or, you're just another victim of this bug: http://bugs.sun.com/view_bug.do?bug_id=4787931. It's a very old bug (more than 6 years old) that affects all versions up till Java 1.6.x.
On Windows 7, how does Java JVM set user.home System property?
This Java bug explains how: http://bugs.sun.com/view_bug.do?bug_id=4787931
System property user.home
is set by:
- Read the registry value for key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop
- 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
Maven doesn't recognize my user profile and looks for .m2 in another location
Turns out that my problem is more of this nature: https://stackoverflow.com/a/2134775/237925. I have tons of references to C:\Users\Administrator in the
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Getting the user home path in application.properties in Spring Boot
I believe I have solved the problem. The log file in question was actually being generated in the class path only when run from the IDE (Eclipse Luna FYI). Later on when I made a jar file and ran that, the log file was being generated in the right location as specified in the application.properties
file. I still have no clue to why it was generated in the class path when I ran it from Eclipse.
What determines the location of the .grails directory?
The grailsWorkDir
property controls the location. You can change the value in the BuildConfig.groovy file.
See the Grails documentation section 5.5 Customising the build:
There is an issue with Java and the user.home
property in Windows. See this SO question for more details:
Java user.home is being set to %userprofile% and not being resolved
user.home in windows ts running eclipse rcp project
Turns out the "Home" key was not set up in the users directory. It could be fixed by following the directions in the answer found here. Java user.home is being set to %userprofile% and not being resolved
Related Topics
Soap Request to Webservice with Java
Attach the Source in Eclipse of a Jar
Java Implementation of JSON to Xml Conversion
Is Concurrenthashmap Totally Safe
How to Select an Item from a Dropdown List Using Selenium Webdriver with Java
How to Get Http Response Code for a Url in Java
Check If File Exists on Remote Server Using Its Url
Java Web Service Client Basic Authentication
Spring 3 MVC: One-To-Many Within a Dynamic Form (Add/Remove on Create/Update)
Comparing Date Strings in Java
Location of Hibernate.Cfg.Xml in Project
How to Shutdown an Executorservice
Java Stanford Nlp: Part of Speech Labels
How to Write Swap Method in Java