java.home is null in recent versions of IDEA

We need to execute an external jar as a standalone application as part of our plugin. This used to work rather well for us by checking the System properties for java.home and then just running the java command line based on that.
Unfortunately this stopped working and it seems the value of java.home is null which seems to be pretty odd.

Is there a better way to run the java command line from within IDEA?
Is there a way to detect the java home dir?


Comment actions Permalink

That definitely is odd, and I found no evidence of IDEA resetting the property. I'd suggest you to set a breakpoint in System.clearProperty() and catch a violator.

Another option is to use a JDK configured for a project:

Sdk sdk = jdk.ProjectRootManager.getInstance(project).getProjectSdk();
String java = ((JavaSdkType)sdk.getSdkType()).getVMExecutablePath(sdk);

(don't forget all the necessary checks).

Comment actions Permalink

Thanks, I'll try to use the project SDK and see if that helps.


Please sign in to leave a comment.