简体   繁体   English

Java 版本在 windows 命令提示符下没有变化

[英]Java version does not change in windows command prompt

I am trying to change my java version because of compiler errors when running mvn install via the windows command prompt.由于在通过 windows 命令提示符运行mvn install时出现编译器错误,我正在尝试更改我的 java 版本。 I changed the JAVA_HOME variable and made sure that it is referenced in the PATH variable ( ##EDIT## : had been done like this %JAVA_HOME%\bin;%PATH%; ).我更改了 JAVA_HOME 变量并确保它在 PATH 变量中被引用( ##EDIT## :已经像这样完成了%JAVA_HOME%\bin;%PATH%; )。

When I open the command prompt in the folder where my pom.exe is located (using the Windows 7 'Open command window here' shortcut) and type java -version the unchanged java version is displayed.当我在我的 pom.exe 所在的文件夹中打开命令提示符时(使用 Windows 7 'Open command window here'快捷方式)并键入java -version显示未更改的 java 版本。

I made sure to close all instances of command prompts before starting a new one.在开始新命令提示之前,我确保关闭所有命令提示实例。 Strangely I discovered that when starting the command prompt via the Run dialog in the start menu (by typing cmd ) the result of java -version is the desired version.奇怪的是,我发现当通过start menu中的Run dialog启动命令提示符时(通过键入cmd ), java -version的结果是所需的版本。

You need to modify path variable as well as below: 您需要修改路径变量以及以下内容:

PATH=%JAVA_HOME%/bin;%PATH%

Post that make sure you open a new command prompt and rerun maven command. 发布确保您打开新命令提示符并重新运行maven命令的帖子。

When using the 'Open command window here' shortcut make sure to close and open the respective explorer window . 使用'Open command window here'快捷方式时,请确保关闭并打开相应的资源管理器窗口 When starting the command prompt in this way Windows uses cached environment variables and does therefore not retrieve the current version of java. 当以这种方式启动命令提示符时,Windows使用缓存的环境变量,因此不会检索Java的当前版本。


Took me a while to figure out because it was too surprising to expect this behavior. 花了我一段时间才弄清楚,因为期望这种行为太令人惊讶了。 Before I was searching on google and stackoverflow.com without any results. 在我搜索google和stackoverflow.com之前,没有任何结果。 Hope this saves someone the trouble. 希望这可以避免麻烦。

In my case worked the following: after editing the environment variables, and checking by command line java -version and javac -version , javac was updated but not java, so you have to do it by command line also set path=C:\Program Files\Java\jdk1.8.0_181\bin在我的案例中,工作如下:编辑环境变量并通过命令行java -versionjavac -version检查后,javac 已更新但 java 未更新,因此您必须通过命令行也set path=C:\Program文件\Java\jdk1.8.0_181\bin

Remove the existing JRE setups.. 删除现有的JRE设置。

Install the one that you need to install. 安装您需要安装的一个。 Hope you have added it in the environment variable and path via settings... Test it, it should work!. 希望您已通过设置将其添加到环境变量和路径中...测试它,应该可以使用!

The same thing happened to me long ago, It was pointing to the older JRE, got stuck, so removed the existing JDKs and installed a fresh copy. 很久以前,我发生了同样的事情,它指向的是较旧的JRE,被卡住了,因此删除了现有的JDK,并安装了一个新副本。 It worked. 有效。

I too faced this problem where I want to change the java version in command prompt but failed. 我也想在命令提示符下更改Java版本时遇到了这个问题,但是失败了。 But finally I succeeded doing the below steps. 但最后我成功完成了以下步骤。 First I'll show the failed attempt, followed by the actual success step so you will know the difference. 首先,我将显示失败的尝试,然后显示实际的成功步骤,以便您了解不同之处。

Failed Step: 失败的步骤:
1. Win + R 1. Win + R
2. Type cmd and hit enter 2.输入cmd然后按Enter
3. Type java -version (Just to check if the version is the old one which we need to change) 3.键入java -version (只需检查版本是否是我们需要更改的旧版本)
4. Now try changing the path/classpath using set path=/classpath= 4.现在尝试使用set path = / classpath =更改路径/ classpath
5. Now again type java -version (This will still show the old java version but not the new version which we set) 5.现在再次键入java -version (这将仍然显示旧的Java版本,而不显示我们设置的新版本)

Success Step: 1. Win + R 成功步骤:1. Win + R
2. Type open command window here and hit enter 3. Type java -version (Just to check if the version is the old one which we need to change) 2. open command window here键入open command window here然后按Enter。3.输入java -version (只需检查版本是否是我们需要更改的旧版本)
4. Now try changing the path/classpath using set path=/classpath= 4.现在尝试使用set path = / classpath =更改路径/ classpath
5. Now again type java -version and voila I see the changed java version here 5.现在再次键入java -version和voila,我在这里看到更改后的Java版本

Thanks! 谢谢!

I had the same problem too. 我也有同样的问题。 After setting the JAVA_HOME, i couldn't see the new value in command prompt even though I started a new command prompt. 设置JAVA_HOME之后,即使启动了新的命令提示符,我也无法在命令提示符下看到新值。

Strangely, it only occured when opening the command prompt from the Windows Explorer. 奇怪的是,它仅在从Windows资源管理器中打开命令提示符时发生。

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

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