开发者

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

开发者 https://www.devze.com 2022-12-17 07:00 出处:网络
Our company recently upgraded from Windows XP to Windows 7 Enterprise. The JDK installation is no longer setting user.home to the full path of the user directory, but instead is setting user.home to %

Our company recently upgraded from Windows XP to Windows 7 Enterprise. The JDK installation is no longer setting user.home to the full path of the user directory, but instead is setting user.home to %userprofile%. This is causing a lot of issues with applications such as Eclipse, Maven, etc. I now have to set -Duser.home in the JVM for each application. Has anyone else experienced this? Is there a fix for this? Would this be related to the installation of Windows 7 Enterprise? I have tried the 1.5 JDK and the 1.6 JDK.

Here is the list of properties. Note user.home:

-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jre6\bin
java.vm.version=16.0-b13
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\Users\politesp\Desktop
java.runtime.version=1.6.0_18-b07
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jre6\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\Users\politesp\AppData\Local\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows 7
sun.jnu.encoding=Cp1252
java.library.path=C:\WINDOWS\system32;.;C:\WINDOWS\Sun\...
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=6.1
user.home=%userprofile%
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.6
user.name=politesp
java.class.path=.
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files\Java\jre6
java.specification.vendor=Sun Microsystems Inc.
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_18
java.ext.dirs=C:\Program Files\Java\jre6\lib\ext;C:...
sun.b开发者_JS百科oot.class.path=C:\Program Files\Java\jre6\lib\resour...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...

Update:

Using the link to the bug from Andreas_D I discovered:

The value of HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop is %userprofile%\Desktop on my installation of Windows 7 Enterprise.

When I change the value of this key to C:\Users\politesp\Desktop, my user.home resolves correctly. Any idea why this is happening?


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


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..


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/


Single string values in registry have 2 types "REG_SZ" and "REG_EXPAND_SZ" and they treat "%data%" strings differently.

Type "REG_SZ" leaves any "%data%" as is.

Type "REG_EXPAND_SZ" replaces "%data%" the "data" environment variable value if defined otherwise no resolution takes place.

The Windows GUI environment variable editing applets selects the correct type depending if "%name%" appears in the value field.

This issue sounds like an installer making poor choices when writing into the registry.

0

精彩评论

暂无评论...
验证码 换一张
取 消