Java user.home 被设置为 %userprofile% 并且没有被解析
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2134338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java user.home is being set to %userprofile% and not being resolved
提问by Dan Polites
Our company recently upgraded from Windows XP to Windows 7 Enterprise. The JDK installation is no longer setting user.hometo 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.
我们公司最近从 Windows XP 升级到了 Windows 7 Enterprise。JDK 安装不再将user.home设置为用户目录的完整路径,而是将 user.home 设置为%userprofile%
. 这会导致 Eclipse、Maven 等应用程序出现很多问题。我现在必须在 JVM 中为每个应用程序设置 -Duser.home。有没有其他人经历过这种情况?有没有办法解决这个问题?这是否与 Windows 7 Enterprise 的安装有关?我试过 1.5 JDK 和 1.6 JDK。
Here is the list of properties. Note user.home:
这是属性列表。注意 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.boot.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:
使用 Andreas_D 的错误链接,我发现:
The value of HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop
is %userprofile%\Desktopon my installation of Windows 7 Enterprise.
的价值HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop
就是%USERPROFILE%\桌面上的我的安装的Windows 7企业版。
When I change the value of this key to C:\Users\politesp\Desktop
, my user.home resolves correctly. Any idea why this is happening?
当我将此键的值更改为 时C:\Users\politesp\Desktop
,我的 user.home 会正确解析。知道为什么会这样吗?
采纳答案by Dan Polites
The majority of the registry keys located at:
大多数注册表项位于:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell 文件夹
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.
开始于%userprofile%
。我更新了所有%userprofile%
以 开头的注册表项C:\Users\myusername
。我在 Windows XP 上验证了路径实际上是硬编码的并且%userprofile%
没有使用。IT 人员提到,%userprofile%
由于在 Windows 7 中使用了默认配置文件,因此默认使用注册表项。 JVM 期望桌面路径是硬编码的。它不会评估环境变量。
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.
- 转到“开始”>“运行”。
- 键入
regedit
。这将打开注册表编辑器。 - 浏览到
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
. - 右键单击
Shell Folders
并选择导出。 - 选择桌面作为目的地并输入
Shell Folders
文件名并保存文件。 - 在文本编辑器中打开文件并替换
%userprofile%
为C:\\Users\\yourusername
. 保存并关闭文件。 - 返回注册表编辑器窗口并从主菜单中选择文件 > 导入。
- 选择
Shell Folders.reg
并单击打开。 - 关闭注册表编辑器并
Shell Folders.reg
从桌面上删除该文件。
回答by Andreas Dolk
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?
在我看来,好像 - 无论出于何种原因 -%USERPROFILE%
都没有被设置为一个值。如果你echo %USERPROFILE%
在命令 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
也许这不是操作系统功能,而是配置问题。在我的机器上 (Vista)%USERPROFILE%
解析到我的主目录,它与 Java 属性相同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..
这是 USERPROFILE 和 user.home: bug的 Vista/Windows7 问题。可能无法解决您的问题可能会给您一个想法..
回答by Brett
This is due to an long outstanding bug in Java: http://bugs.sun.com/view_bug.do?bug_id=4787931
这是由于 Java 中一个长期未解决的错误:http: //bugs.sun.com/view_bug.do?bug_id=4787931
回答by Luka Brade?ko
Until Java 8 where this is fixed, the solution is to add this into the environment variables:
_JAVA_OPTIONS:-Duser.home=%HOMEDRIVE%%HOMEPATH%
在 Java 8 修复此问题之前,解决方案是将其添加到环境变量中:
_JAVA_OPTIONS:-Duser.home=%HOMEDRIVE%%HOMEPATH%
or in command line:
set _JAVA_OPTIONS=-Duser.home=%HOMEDRIVE%%HOMEPATH%
或在命令行中:
设置 _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/
我在这个页面的评论中看到了解决方案:http: //www.timehat.com/javas-user-home-is-wrong-on-windows/
回答by Conrad T. Pino
Single string values in registry have 2 types "REG_SZ"
and "REG_EXPAND_SZ"
and they treat "%data%"
strings differently.
注册表中的单个字符串值有 2 种类型"REG_SZ"
,"REG_EXPAND_SZ"
并且它们以"%data%"
不同的方式处理字符串。
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.
类型"REG_EXPAND_SZ"
替换"%data%"
的"data"
,如果定义,否则没有解决发生的环境变量的值。
The Windows GUI environment variable editing applets selects the correct type depending if "%name%"
appears in the value field.
Windows GUI 环境变量编辑小程序根据"%name%"
值字段中是否出现来选择正确的类型。
This issue sounds like an installer making poor choices when writing into the registry.
这个问题听起来像是安装程序在写入注册表时做出了错误的选择。