简体   繁体   English

windows 上的 java 版本冲突

[英]java version conflict on windows

I usually work with java 11 on my computer but then I installed java 8 to run both.我通常在我的计算机上使用 java 11 但后来我安装了 java 8 来运行两者。

Now when I run java -version, it shows java 8. I find it odd because my environment variables point towards 11. In addition javac -version shows 11. Seems it's not clear to my system which one is the current version.现在,当我运行 java -version 时,它显示 java 8。我觉得这很奇怪,因为我的环境变量指向 11。此外 javac -version 显示 11。我的系统似乎不清楚哪个是当前版本。

I try many solution I found here but nothing seems to work, unless I uninstall java 8.我尝试了很多我在这里找到的解决方案,但似乎没有任何效果,除非我卸载 java 8。

How can I resolve this and cleanly switch between both (or many) java version on my pc?如何解决这个问题并在我的电脑上的两个(或多个)java 版本之间干净地切换?

The operating system on your computer uses the PATH environment variable to locate the javac executable.您计算机上的操作系统使用 PATH 环境变量来定位javac可执行文件。 Hence the bin subdirectory of your JDK 11 installation appears in the value of the PATH environment variable.因此,JDK 11 安装的bin子目录出现在 PATH 环境变量的值中。 Note that the bin subdirectory of your JDK 8 installation may also appear in the value of PATH but since you say that javac -version shows 11, that means that if both JDK 11 bin and JDK 8 bin are on the PATH then JDK 11 appears before JDK 8. That's why, when you issue javac -version it shows 11.请注意,JDK 8 安装的bin子目录也可能出现在 PATH 的值中,但由于您说javac -version显示 11,这意味着如果 JDK 11 bin和 JDK 8 bin都在 PATH 上,则 JDK 11 出现在前面JDK 8。这就是为什么当您发出javac -version时它显示 11。

Regarding the output of command java -version that depends on other details which I could not find in your question, including (but not only) which JDK 8 you installed.关于命令 java 的java -version取决于我在您的问题中找不到的其他详细信息,包括(但不仅是)您安装了哪个 JDK 8。 If it is Oracle's and if you installed JDK 8 after you installed JDK 11, that would explain why java -version shows 8.如果它是 Oracle 的并且如果您在安装 JDK 11之后安装了 JDK 8,那就可以解释为什么java -version显示 8。

Note that if you want to run a specific JDK, you can always enter the full path to the file java.exe when you enter the command - rather than just java .请注意,如果您想运行特定的 JDK,您始终可以在输入命令时输入文件java.exe的完整路径,而不仅仅是java

On windows 10, you have to change both JAVA_HOME and Path .在 windows 10 上,您必须同时更改JAVA_HOMEPath

  1. Change JAVA_HOME to point towards your desired version.更改JAVA_HOME以指向您想要的版本。
  2. In Path make sure the desired version comes before the other one.Path中确保所需的版本另一个之前。

This works for me(i switch frequently between java 8 and 11).这对我有用(我经常在 java 8 和 11 之间切换)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM