Windows – 从java代码中编程查找绝对的java.exe路径

前端之家收集整理的这篇文章主要介绍了Windows – 从java代码中编程查找绝对的java.exe路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我有一个由用户启动的 java jar或类文件(假设 java路径设置在环境变量中),那么我如何从代码中找出java.exe / javaw.exe的绝对路径文件正在启动.

像ubuntu一样,我们可以运行:%哪个java和它显示的路径.

但是在Windows上,如果我检查System.getenv(),可能会出现多个路径,例如旧版本或新版本.如果通过cmd行,我运行java -version它不会显示路径.

你可以通过纯Java或Windows上的命令行告诉我如何可以找出javaw.exe的位置?

String javaHome = System.getProperty("java.home");

Can you tell me either through pure Java … on windows how is it possible to find out the location of javaw.exe?

例如.

import java.io.File;

class JavawLocation {

    public static void main(String[] args) {
        String javaHome = System.getProperty("java.home");
        File f = new File(javaHome);
        f = new File(f,"bin");
        f = new File(f,"javaw.exe");
        System.out.println(f + "    exists: " + f.exists());
    }
}

产量

C:\Program Files (x86)\Java\jdk1.6.0_29\jre\bin\javaw.exe    exists: true
Press any key to continue . . .

是的,我有信心在JRE工作.

原文链接:https://www.f2er.com/windows/370571.html

猜你在找的Windows相关文章