简体   繁体   English

dos中的“ java”命令如何找到要使用的jre

[英]how “java” command in dos find which jre to use

if one computer installed more than one jdk and jre, I want to know, when I excute "java" command in dos, how "java" command find which jre it should use? 如果一台计算机安装了多个jdk和jre,我想知道,当我在dos中执行“ java”命令时,“ java”命令如何找到应该使用的jre? I saw a answer in somewhere, he said there there step to search jre: 我在某处看到一个答案,他说在那儿搜索jre:

  1. search the current directory which java.exe placed to find the JRE directory 搜索java.exe放置的当前目录以找到JRE目录

  2. search the parent directory to find JRE directory 搜索父目录以查找JRE目录

  3. search the JRE directory based on the [HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment] information in registry 根据注册表中的[HKEY_LOCAL_MACHINE \\ SOFTWARE \\ JavaSoft \\ Java Runtime Environment]信息搜索JRE目录

It is right? 这是正确的?

The Java command from a dos prompt is handled as any other dos command is. 与其他任何dos命令一样,将处理dos提示符下的Java命令。

That means it searches the PATH environment variable and the current folder. 这意味着它将搜索PATH环境变量和当前文件夹。

If you want to run a specific version then use the full path to the version of Java you want to run. 如果要运行特定版本,请使用要运行的Java版本的完整路径。

If you want to always run a specific version then change your PATH environment variable accordingly. 如果要始终运行特定版本,请相应地更改PATH环境变量。

The Java command will have come bundled with a particular JRE/JDK and will use that when executing. Java命令将与特定的JRE / JDK捆绑在一起,并在执行时使用它。

When you execute java command, it depends on the PATH variable and the current directory. 执行java命令时,它取决于PATH变量和当前目录。 Java comes with bundled JRE which will be used. Java附带了将使用的捆绑JRE。 If you want to change to different version, then either need to change it in the PATH variable or execute it using the absolute path of java.exe. 如果要更改为其他版本,则需要在PATH变量中进行更改,或者使用java.exe的绝对路径执行它。

When you write 'java' in the command line in windows, it will only do one thing: 在Windows的命令行中编写“ java”时,它只会做一件事:

Look if there is something called like that in your PATH , and call the first one that it finds. 查看PATH是否有类似的名称,并调用它找到的第一个名称。

Maybe you are asking about the java.exe stub that the JRE installation places in Windows/System32 (that is normally by default in the PATH ). 也许您正在询问JRE安装在Windows / System32中放置的java.exe存根(通常默认情况下在PATH )。 That is not a full JRE, but a simple ad-hoc program which tries to do what you have described in your 3rd point. 那不是一个完整的JRE,而是一个简单的临时程序,它试图完成您在第三点中描述的事情。

As Marko Topolnik said, there is java.exe in \\windows\\system32, I test ,I delete the java.exe file in jdk bin folder, when I execute "java" command, it aslo can work, so it said that when execute "java" command in DOS, it actual execute java.exe in outer JRE bin folder, not the JDK bin java.exe. 正如Marko Topolnik所说,\\ windows \\ system32中有java.exe,我测试了一下,删除了jdk bin文件夹中的java.exe文件,当我执行“ java”命令时,它也可以正常工作,因此它说执行时在DOS中使用“ java”命令,它实际上在外部JRE bin文件夹中执行java.exe,而不是在JDK bin java.exe中执行。 so I think the PATH didn't use for search JRE, is it right? 所以我认为PATH并未用于搜索JRE,对吗?

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

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