简体   繁体   English

Java 版本命令给出不同的结果

[英]Java version command giving different results

I have set the environment variable for Java 7 but some software are picking Java 1.8 as default.我已经为 Java 7 设置了环境变量,但有些软件选择 Java 1.8 作为默认值。 When I am checking version through command prompt it is giving different results.当我通过命令提示符检查版本时,它给出了不同的结果。 How and why is this happening?这是如何以及为什么发生的?

C:\Users\TanuGarg>java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

C:\Users\TanuGarg>javac -version
javac 1.7.0-internal

this happens because you have two java versions (JRE) installed in your pc (one used by software and the other one is your jre in your JDK) and you have only one SDK version so your javac.发生这种情况是因为您的 PC 中安装了两个 Java 版本 (JRE)(一个由软件使用,另一个是您的 JDK 中的 jre)并且您只有一个 SDK 版本,因此您的 javac.

Solution:解决方案:

Set Path variable to your JDK bin folder and remove the path of the other jre from Path Variable.将 Path 变量设置为您的 JDK bin 文件夹,并从 Path Variable 中删除其他 jre 的路径。

you can go to control panel -> java -> java (tab) -> View.您可以转到control panel -> java -> java (tab) -> View. This will list all the jre that are currently installed on your system(Where java will achieve the same thing).这将列出您系统上当前安装的所有 jre(其中 java 将实现相同的功能)。 Here you can disable the jre-8 or any jre that might be latest install on your system by unchecking the Enable checkbox.在这里,您可以通过取消选中Enable复选框来禁用 jre-8 或系统上可能最新安装的任何 jre。

Also, if you want to run a software for a specific jre on a system that have multiple jre instanlled, you can directly go the jave jre path and run java mysoftware command from there此外,如果您想在安装了多个 jre 的系统上运行特定 jre 的软件,您可以直接转到 jave jre 路径并从那里运行java mysoftware命令

eg C:\\Program Files\\IBM\\Java70\\bin > java mycommand

If you have several jdks in your environment like me then, the only thing you can do is setting a proper path variable for your desirable jdk.如果你的环境中有几个 jdk,那么你唯一能做的就是为你想要的 jdk 设置一个正确的路径变量。

In my case, i have three jdks- 1.6, 1.7 and 1.8(javafx).就我而言,我有三个 jdks-1.6、1.7 和 1.8(javafx)。

我的三个jdk文件夹

I have three jdk choices depending on the path variables.根据路径变量,我有三个 jdk 选择。

For java 8 choice, i have to set the path variable look like image below.对于 java 8 选择,我必须设置路径变量,如下图所示。

在此处输入图片说明

where my javac.exe file is located under the folder name我的 javac.exe 文件位于文件夹名称下的位置

C:\\DEV\\COMP\\Java\\javafx\\jdk1.8.0_152 C:\\DEV\\COMP\\Java\\javafx\\jdk1.8.0_152

For java 7, i just set the path again pointing another one of jdk folders - jdk7.对于 java 7,我只是再次设置路径指向另一个 jdk 文件夹 - jdk7。

在此处输入图片说明

It depends on which java version you should use by changing your java path if you just set the path variable properly.如果您只是正确设置了路径变量,这取决于您应该通过更改 java 路径来使用哪个 java 版本。

Let's see the path variables so far.让我们看看到目前为止的路径变量。

在此处输入图片说明

The default jdk version is 1.7 because first item on a path variable is pointed at the jdk 1.7 path.默认 jdk 版本是 1.7,因为路径变量上的第一项指向 jdk 1.7 路径。 I get a jdk 8 version, if I move the path of jdk 1.8 before that of jdk 1.7 again.如果我再次将 jdk 1.8 的路径移动到 jdk 1.7 的路径之前,我会得到一个 jdk 8 版本。

在此处输入图片说明

I have set the environment variable for Java 7 but some software are picking Java 1.8 as default.我已经为Java 7设置了环境变量,但是某些软件选择Java 1.8作为默认变量。 When I am checking version through command prompt it is giving different results.当我通过命令提示符检查版本时,会给出不同的结果。 How and why is this happening?这是怎么发生的,为什么呢?

C:\Users\TanuGarg>java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

C:\Users\TanuGarg>javac -version
javac 1.7.0-internal

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

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