Checking/getting JAVA_HOME Variable from Java

antonio picture antonio · Apr 30, 2013 · Viewed 16k times · Source

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.

Answer

Thilo picture Thilo · Apr 30, 2013

Try

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