34

It it possible to get the location of the jre that is used for the current process. Need to launch an other java application as a separate process. Having different jre's available (and no path variable set) I would like ask eg. the loader for this. Running on Solaris, Linux, Windows.

owan
  • 341
  • 1
  • 3
  • 3

3 Answers3

47

You can use:

System.getProperty("java.home")

http://download.oracle.com/javase/6/docs/api/java/lang/System.html#getProperties%28%29 says:

java.home: Java installation directory

Hendrik Brummermann
  • 8,242
  • 3
  • 31
  • 55
  • 3
    .. and what if another JRE was used to start the currently running JVM (which I believe is possible, correct me if I'm wrong), i.e., no the one installed in JAVA_HOME? – Art Licis Dec 25 '10 at 20:52
  • 4
    It returns the path to the JRE that is used to run the program which does the lookup. It is not related to JAVA_HOME. – Hendrik Brummermann Dec 25 '10 at 20:56
10
System.getProperty("java.home")
1

System.out.println(System.getProperty("java.home"));

The code above will return the full physical path to current jvm's jre path. Tested only in Windows 10.

Asalle
  • 1,239
  • 19
  • 41