Programmatically Get Absolute Path of Java Executable in a Running Program

Do you want to get absolute path of the specific Java executable that was used to launch a program, from within that program itself? May be you want to launch another Java program P2 from a program P1 and you want to make sure that P2 is launched using the same version of Java that was used to launch P1?

It is possible. Java runtime makes available a system property  java.home which contains the path to its installation or root directory. Java executable is usually located (tested on Windows and Mac) inside  java.home in a folder named  bin . We can combine these two facts to get absolute path of the Java executable that was originally used to launch a program. Here is a code snippet that does exactly this:

You will need to import  java.io.File in your source code to compile it. After these couples of lines have executed,  javaExe will contain our required path. You can use it for whatever purpose you want. Here is a sample code snippet that uses this Java executable to launch another Java program in a separate JVM. Continue reading Programmatically Get Absolute Path of Java Executable in a Running Program

SOLUTION: No Java runtime present, requesting install – Mac OS X Yosemite

I was working on a simple java based desktop application today. It was packaged in an executable jar. One of its required features was to launch another executable jar in a separate instance of JVM. Here is my code dealing with this requirement:

This is equivalent of running following command on terminal.

This code was working fine on Windows and Ubuntu. But on Mac, it resulted in a dialogue like this: Continue reading SOLUTION: No Java runtime present, requesting install – Mac OS X Yosemite