Friday, November 5, 2010

Trouble with user.home under Local System account on Windows

I was working on setting up a Hudson server and bunch of ant build jobs when I stumbled across an old, very old bug, of the JDK #4787931. The bug showed itself when I tried to run an ant job which was using Ivy for dependency resolution:


Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -C:\Hudson\tools\Ant_1.7\lib
        -C:\Documents and Settings\someusername\.ant\lib
        -a directory added on the command line with the -lib argument
Obviously, the C:\Documents and Settings\someusername is not the right home directory where Ant should be locking for additionally library. The location of .ant/lib directory is determine by the user.home system property. In this case, user.home should have been C:\windows\system32\config\systemprofile since the server was running as Local System account. However, thanks to above mention bug the location of the user.home is determine by the 'Desktop' registry key at HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders. In my case that seem to be pointing out to the particular directory.


The solution turn to be simple enough. Just run the following line on the target machine :
reg add "HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" \
/v Desktop /t REG_SZ /d "C:\Hudson\Desktop" /f
That is if you want the user.home to point to be C:\Hudson.