windows Groovy Shell 警告“无法打开/创建首选项根节点......”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16428098/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:29:18  来源:igfitidea点击:

Groovy Shell warning "Could not open/create prefs root node ..."

windowsgroovygroovyshell

提问by Dennis Traub

I tried to open the Groovy Shell (groovysh) on Windows 8 and got the following output:

我尝试groovysh在 Windows 8 上打开 Groovy Shell ( ) 并得到以下输出:

java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs 
at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

After printing the above message the shell started as expected.

打印上述消息后,shell 按预期启动。

回答by MKorsch

Dennis answer is correct. However I would like to explain the solution in a bit more detailed way (for Windows User):

丹尼斯的回答是正确的。但是,我想以更详细的方式解释解决方案(对于 Windows 用户):

  1. Go into your Start Menu and type regeditinto the search field.
  2. Navigate to path HKEY_LOCAL_MACHINE\Software\JavaSoft(Windows 10 seems to now have this here: HKEY_LOCAL_MACHINE\Software\WOW6432Node\JavaSoft)
  3. Right click on the JavaSoft folder and click on New-> Key
  4. Name the new Key Prefsand everything should work.
  1. 进入开始菜单并regedit在搜索字段中输入。
  2. 导航到路径HKEY_LOCAL_MACHINE\Software\JavaSoft(10的Windows似乎现在有这样的位置:HKEY_LOCAL_MACHINE\Software\WOW6432Node\JavaSoft
  3. 右键单击 JavaSoft 文件夹,然后单击New->Key
  4. 命名新密钥Prefs,一切都应该正常工作。

Alternatively, save and execute a *.regfile with the following content:

或者,保存并执行*.reg包含以下内容的文件:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs]

回答by Dennis Traub

I was able to resolve the problem by manually creating the following registry key:

我能够通过手动创建以下注册表项来解决该问题:

HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs

回答by peterh

This is actually a JDK bug. It has been reported several times over the years, but only in 8139507was it finally taken seriously by Oracle.

这实际上是一个JDK错误。多年来,它已被多次报道,但只有在8139507 中,它才最终被 Oracle 认真对待。

The problem was in the JDK source code for WindowsPreferences.java. In this class, both nodes userRootand systemRootwere declared static as in:

问题出在WindowsPreferences.java. 在这个类中,节点userRootsystemRoot都被声明为静态,如下所示:

/**
 * User root node.
 */
static final Preferences userRoot =
     new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);

/**
 * System root node.
 */
static final Preferences systemRoot =
    new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);

This means that the first time the class is referenced bothstatic variables would be initiated and by this the Registry Key for HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs(= system tree) will be attempted to be created if it doesn't already exist.

这意味着第一次引用该类时,将启动两个静态变量,如果HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs(= 系统树)的注册表项尚不存在,则将尝试创建它。

So even if the user took every precaution in his own code and never touched or referenced the system tree, then the JVM would actually still try to instantiate systemRoot, thus causing the warning. It is an interesting subtle bug.

因此,即使用户在自己的代码中采取了所有预防措施并且从未接触或引用系统树,那么 JVM 实际上仍会尝试实例化systemRoot,从而导致警告。这是一个有趣的微妙错误。

There's a fix committed to the JDK source in June 2016 and it is part of Java9 onwards. There's also a backportfor Java8 which is in u202.

2016 年 6 月对 JDK 源代码进行了修复,它是 Java9 以后的一部分。在u202 中还有一个Java8 的反向移植

What you see is really a warning from the JDK's internal logger. It is not an exception. I believe that the warning can be safely ignored .... unless the user code is indeed wanting the system preferences, but that is very rarely the case.

您看到的实际上是来自 JDK 内部记录器的警告。这也不例外。我相信可以安全地忽略警告......除非用户代码确实需要系统首选项,但这种情况很少见。

Bonus info

奖金信息

The bug did not reveal itself in versions prior to Java 1.7.21, because up until then the JRE installer would create Registry key HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefsfor you and this would effectively hide the bug. On the other hand you've never really been required to run an installer in order to have a JRE on your machine, or at least this hasn't been Sun/Oracle's intent. As you may be aware Oracle has been distributing the JRE for Windows in .tar.gzformat for many years.

该错误在 Java 1.7.21 之前的版本中并未出现,因为在此之前 JRE 安装程序会HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs为您创建注册表项,这将有效地隐藏该错误。另一方面,您从未真正需要运行安装程序才能在您的机器上安装 JRE,或者至少这不是 Sun/Oracle 的意图。您可能知道,Oracle 多年来一直以.tar.gz格式分发适用于 Windows 的 JRE 。

回答by walkern

If anyone is trying to solve this on a 64-bit version of Windows, you might need to create the following key:

如果有人试图在 64 位版本的 Windows 上解决此问题,您可能需要创建以下密钥:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Prefs

回答by Darksnake

The problem is that simple console can't edit the registry. No need to edit the registry by hand, just launch the groovyshonce with administrative priveleges. All subsequent launches work without error.

问题是简单的控制台无法编辑注册表。无需手动编辑注册表,只需groovysh使用管理权限启动一次即可。所有后续启动工作都没有错误。

回答by razvanone

Had a similar problem when starting apache jmeter on windows 8 64 bit:

在 Windows 8 64 位上启动 apache jmeter 时遇到了类似的问题:

[]apache-jmeter-2.13\bin>jmeter
java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs     at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

Successfully used Dennis Traub solution, with Mkorsch explanations. Or you can create a file with the extension "reg" and write into it the following:

成功使用 Dennis Traub 解决方案,并附有 Mkorsch 解释。或者,您可以创建一个扩展名为“reg”的文件,并在其中写入以下内容:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs]

... then execute it.

...然后执行它。

回答by Sohail Ahmed

I was getting the following message:

我收到以下消息:

Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002

and it was gone after creating one of these registry keys, mine is 64 bit so I tried only that.

在创建这些注册表项之一后它就消失了,我的是 64 位,所以我只尝试过。

32 bit Windows
HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs

64 bit Windows
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Prefs

回答by Wolsie

This happened to me.

这发生在我身上。

Apparently it is because Java does not have permission to create registry keys.

显然这是因为 Java 没有创建注册表项的权限。

See: Java: java.util.Preferences Failing

请参阅:Java:java.util.Preferences 失败

回答by Alessandro Roaro

The problem is indeed the register key that is missing. It can be created manually

问题确实是缺少注册密钥。可以手动创建

OR

或者

it can be created automagicallyby running the program as administrator once. That will give the program the permissions required, and when it will be ran as normal it will still work correctly.

它可以通过以管理员身份运行程序一次自动创建。这将为程序提供所需的权限,当它正常运行时,它仍然可以正常工作。