从 java 中查找 java.exe 位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19369769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find the java.exe location from java
提问by Konstantin Tarashchanskiy
I am wondering if there is a way, from java, to find the location of the java.exe running the program?
我想知道是否有办法从 java 中找到运行程序的 java.exe 的位置?
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.
我的用例是我试图让 Java 执行一个需要在本地环境中设置 JAVA_HOME 的批处理脚本。我在其上执行此操作的环境可能没有设置 JAVA_HOME 甚至路径上的 java 可执行文件,但我假设 JVM 知道其可执行文件所在的位置。
采纳答案by Sage
System.getProperty("java.home");
is one option. Which shows the following directory in my machine:
是一种选择。其中显示了我机器中的以下目录:
C:\Program Files\Java\jdk1.7.0_02\jre
C:\Program Files\Java\jdk1.7.0_02\jre