在 Java 32 位和 Java 64 位之间切换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8277549/
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
Switch between Java 32-bit and Java 64-bit
提问by Best
I have just found out that Apache Tomcat cannot run as a Windows service if I'm using a 64-bit JDK. Therefore I have additionally installed Java 32-bit on my Windows.
我刚刚发现,如果我使用的是 64 位 JDK,则 Apache Tomcat 无法作为 Windows 服务运行。因此,我在 Windows 上另外安装了 Java 32 位。
The question is when I checked the java version using java -version, it still shows that 64-bit is still running. How do you switch from 64-bit to 32-bit? It would also be nice to have the ability to switch back to 64-bit later as well.
问题是当我使用 java -version 检查 java 版本时,它仍然显示 64 位仍在运行。如何从 64 位切换到 32 位?如果能够稍后再切换回 64 位,那就太好了。
采纳答案by Stephen C
The question is when I checked the java version using java -version, it still shows that 64-bit is still running.
问题是当我使用 java -version 检查 java 版本时,它仍然显示 64 位仍在运行。
That's not strictly true. There is no copy of Java still / already running. (Or if there is, you aren't talking to itwhen you run java -version
.)
这不完全正确。没有 Java 副本仍在/已经在运行。(或者如果有的话,当你运行时你不会和它说话java -version
。)
What this actuallyshows is that your command shell runs a 64-bit Java when you gave it the command name java
. And the reason for that is that shell's %PATH% variable is telling the shell to look in the directory containing the 64-bit version, rather than the 32-bit version; i.e. you haven't changed it!
这实际上表明,当您为其指定命令名称时,您的命令外壳运行的是 64 位 Java java
。原因是 shell 的 %PATH% 变量告诉 shell 在包含 64 位版本而不是 32 位版本的目录中查找;即你没有改变它!
What you need to do is to change the shell's %PATH% and %JAVA_HOME% environment variables to point to the correct place. The %JAVA_HOME% should point to the installation directory, and the %PATH% variable should include %JAVA_HOME%\bin.
您需要做的是更改 shell 的 %PATH% 和 %JAVA_HOME% 环境变量以指向正确的位置。%JAVA_HOME% 应指向安装目录,%PATH% 变量应包含 %JAVA_HOME%\bin。
回答by gd1
You have to set the JAVA_HOME
environment variable to the path of the JDK version you want to use.
您必须将JAVA_HOME
环境变量设置为要使用的 JDK 版本的路径。
For 2000/XP see: http://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
对于 2000/XP,请参阅:http: //confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
For Windows 7 see: http://www.itechtalk.com/thread3595.html(this is not a tutorial to set the JAVA_HOME
variable, but a generic environment variable: please adapt to your needs.)
对于 Windows 7,请参见:http: //www.itechtalk.com/thread3595.html(这不是设置JAVA_HOME
变量的教程,而是通用环境变量:请根据您的需要进行调整。)
If you want to change the Java version you see when running java -version
on the command line, then you have to change the PATH
environment variable so that it contains a path to the bin
directory of the JDK you want to use. See: http://www.java.com/en/download/help/path.xml
Remember to close the command shell and re-open it after you change the PATH
variable.
如果要更改在java -version
命令行上运行时看到的 Java 版本,则必须更改PATH
环境变量,使其包含bin
要使用的 JDK 目录的路径。请参阅:http: //www.java.com/en/download/help/path.xml
请记住关闭命令外壳并在更改PATH
变量后重新打开它。
回答by Andre
I found that on Windows 7, I had to edit the JAVA_HOME
path in the registry entries in multiple places in order to completelyswitch to a different path for another java installation. Changing JAVA_HOME
in the environment variables is not enough. You can do a quick test yourself:
我发现在 Windows 7 上,我必须JAVA_HOME
在多个位置编辑注册表项中的路径才能完全切换到另一个 java 安装的不同路径。改变JAVA_HOME
环境变量是不够的。你可以自己做一个快速测试:
- Rename your Java Home directory.
- Update your
%JAVA_HOME%
environment variable value to reflect the new name of yourJAVA_HOME
. - Run
java -version
in a new command window.
- 重命名您的 Java 主目录。
- 更新您的
%JAVA_HOME%
环境变量值以反映您的JAVA_HOME
. java -version
在新的命令窗口中运行。
You will get an error message saying
你会收到一条错误信息说
Error: could not open `C:\your_java_home_path\jre7\lib\amd64\jvm.cfg'
Therefore, it's not the same behavior as on Linux where simply changing $JAVA_HOME
is enough to change your pointer to a new installation directory of your java.
因此,它与 Linux 上的行为不同,在 Linux 上,只需更改$JAVA_HOME
就足以将指针更改为指向 java 的新安装目录。
Looks like Windows hard codes the java home path in its registry in multiple places.
看起来 Windows 在其注册表中的多个位置对 java 主路径进行了硬编码。
Start --> Run --> regedit
Under HKEY_LOCAL_MACHINE / SOFTWARE / JavaSoft / ...
expand each directory and edit every java home path that you find hard coded to your new JAVA_HOME
path in each registry where it occurs.
在HKEY_LOCAL_MACHINE / SOFTWARE / JavaSoft / ...
展开每个目录并编辑您发现的每个 java 主路径下,这些路径被硬编码到JAVA_HOME
它出现的每个注册表中的新路径。