从Java查找java.exe位置 [英] Find the java.exe location from java

查看:569
本文介绍了从Java查找java.exe位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以通过java找到运行程序的java.exe的位置?

我的用例是我试图让Java执行需要在本地环境中设置JAVA_HOME的批处理脚本.我在其上执行此操作的环境可能没有设置JAVA_HOME甚至在路径上没有java可执行文件,但是我假设JVM知道其可执行文件位于何处.

解决方案

 System.getProperty("java.home");

是一种选择.其中显示了我机器中的以下目录:

C:\ Program Files \ Java \ jdk1.7.0_02 \ jre

此处列出了最重要的系统属性.

I am wondering if there is a way, from java, to find the location of the java.exe running the program?

My use case is that I am trying to have Java execute a batch script that needs JAVA_HOME to be set in the local environment. The environment that I am executing this on may not have JAVA_HOME set or even the java executable on the path, but I would assume that the JVM knows where its executable is located.

解决方案

 System.getProperty("java.home");

is one option. Which shows the following directory in my machine:

C:\Program Files\Java\jdk1.7.0_02\jre

Most important system properties are listed here.

这篇关于从Java查找java.exe位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆