微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/windows/370571.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐