windows R 寻找错误的 Java 版本

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

R looking for the wrong java version

javawindowsr

提问by Veit

I installed/uninstalled java jre/jdk now many times and finally installed the older version 1.6.0_17 which is now located at "C:\Program Files\Java\jre6\bin". Now after all if I call 'java -version' within R i can see that R is looking for Java at the old path which is now wrong. The question is: Why is R looking for Java at the wrong path even so the windows path is set correctly? There are no double entrys within the windows path as far as I can see and I restarted R as well as Windows more then once since then. Any Ideas where R takes the wrong path from?

我现在多次安装/卸载 java jre/jdk,最后安装了旧版本 1.6.0_17,它现在​​位于“C:\Program Files\Java\jre6\bin”。现在毕竟如果我在 R 中调用“java -version”,我可以看到 R 正在旧路径上寻找 Java,但现在是错误的。问题是:即使 Windows 路径设置正确,为什么 R 在错误的路径上寻找 Java?据我所知,Windows 路径中没有双重条目,从那以后我重新启动了 R 和 Windows 一次。R从哪里走错路的任何想法?

On windows shell:
$>set
[..]
OS=Windows_NT
Path=C:\Program Files\Java\jre6\bin;
[..]

在 Windows 外壳上:
$>set
[..]
OS=Windows_NT
Path=C:\Program Files\Java\jre6\bin;
[..]

$> java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

$> java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

within R:
$>system("java -version")
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.cfg'

R内:
$>system("java -version")
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.cfg'

采纳答案by Marek

You problem depends on 64/32 bit versions.
You run 32-bit R, which use 32-bit command prompt and find 32-bit java. If you use 64-bit R then it runs 64-bit command promt and proper java.

您的问题取决于 64/32 位版本。
您运行 32 位 R,它使用 32 位命令提示符并找到 32 位 java。如果您使用 64 位 R,那么它会运行 64 位命令提示符和正确的 java.lang.

You could check it by run 32-bit command promt (following this post):

您可以通过运行 32 位命令提示符来检查它(在这篇文章之后):

  1. Click Start.
  2. Type %windir%\SysWoW64\cmd.exein Start Search box.
  3. Press Enter.
  4. Type java -version
  1. 单击开始。
  2. 键入%windir%\SysWoW64\cmd.exe在开始搜索框中。
  3. 按 Enter。
  4. 类型 java -version

In my system it fails because I don't have 32-bit java. With standard cmd.exe I get proper path.

在我的系统中它失败了,因为我没有 32 位 java。使用标准 cmd.exe 我得到正确的路径。

For possible solution there are two ways. Install 32-bit R and 32-bit Java or 64-bit R (which is officially supported from 2.11 version) and 64-bit Java. On my system (64-bit Windows 7) I've got both sets, so on 32-bit combination I get:

对于可能的解决方案,有两种方法。安装 32 位 R 和 32 位 Java 或 64 位 R(从 2.11 版本正式支持)和 64 位 Java。在我的系统(64 位 Windows 7)上,我有两套,所以在 32 位组合上我得到:

> system("java -version")
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

And on 64-bit:

在 64 位上:

> system("java -version")
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode)

On 64-bit version you could call 32-bit Java using 32-bit cmd:

在 64 位版本上,您可以使用 32 位 cmd 调用 32 位 Java:

shell(
    "java -version",
    shell = file.path(Sys.getenv("windir"),"SysWoW64/cmd.exe")
)
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

About Shane's comment I think the question is how R get path to 32-bit cmd. Because I can't find a way to call 64-bit cmd on 32-bit R.

关于 Shane 的评论,我认为问题是 R 如何获得 32 位 cmd 的路径。因为我找不到在 32 位 R 上调用 64 位 cmd 的方法。

回答by Nathan

I got to this page trying to work out why my JDK was reporting 64 bit despite the PATH and JAVA_HOME were pointing to 32 bit.

我来到这个页面试图弄清楚为什么我的 JDK 报告 64 位,尽管 PATH 和 JAVA_HOME 指向 32 位。

I dont even know what R is, but this article might help (it solved it for me)

我什至不知道 R 是什么,但这篇文章可能会有所帮助(它为我解决了这个问题)

http://www.tipandtrick.net/2008/how-to-open-and-run-32-bit-command-prompt-in-64-bit-x64-windows/

http://www.tipandtrick.net/2008/how-to-open-and-run-32-bit-command-prompt-in-64-bit-x64-windows/

In a nutshell, dont run from 'cmd' use '%windir%\SysWoW64\cmd.exe' instead. Or, put your JDK at the front of the path instead of the end (I dont think this is ideal).

简而言之,不要从 'cmd' 运行,而是使用 '%windir%\SysWoW64\cmd.exe'。或者,将您的 JDK 放在路径的前面而不是末尾(我认为这不理想)。

回答by duffymo

You're assuming that R is looking at the windows path, but the code is telling you that it's not. So check your assumption: R is getting the path somewhere else.

您假设 R 正在查看 windows 路径,但代码告诉您事实并非如此。因此,请检查您的假设:R 正在其他地方获取路径。

If I open up a command shell on my Windows machine and type "java -version" I get this:

如果我在我的 Windows 机器上打开一个命令外壳并输入“java -version”,我会得到这个:

C:\>java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

If I check the PATH on my machine, I get (edited for clarity):

如果我检查机器上的 PATH,我会得到(为了清晰起见进行了编辑):

C:\>set path
Path=;C:\JDKs\jdk1.6.0_13\bin;

If I open up R version 2.8.1 and run system("java -version") I get this:

如果我打开 R 版本 2.8.1 并运行 system("java -version") 我得到这个:

> system("java -version")
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)
>

So, like I said, R is not using my path to find java.exe. It's using something else.

所以,就像我说的,R 没有使用我的路径来查找 java.exe。它正在使用其他东西。

回答by M. Jessup

You may also need to check the registry, R may have its own setting. You can also start regedit and do a search on the path to binary that it is starting.

您可能还需要检查注册表,R 可能有自己的设置。您还可以启动 regedit 并在它启动的二进制文件路径上进行搜索。