Inside a Java program, how can I read the JAVA_HOME
variable (to be sure it is set the correct way)?
Similarly, how can I get the path of the bin
folder? That is, the path usually set in Windows via:
path %path%;%JAVA_HOME%\bin
Note: I am using the OpenJDK build by Alexkasko.
Try
String javaHome = System.getProperty("java.home");
Since both PATH and JAVA_HOME are environment variables, you should be able to read both of their values in a similar way:
String javaHome = System.getenv("JAVA_HOME");
String path = System.getenv("PATH");
Use System.getenv() to read the value.
System.getenv("JAVA_HOME");
You have to use System.getenv("JAVA_HOME");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With