Reto Höhener
Reto Höhener

Reputation: 5808

How to determine at launcher runtime whether the JRE is bundled locally or not?

I'm thinking maybe check if java.home starts with the current execution path, e.g.

<install.dir>/jre

But, launchers can be configured to change the working directory, or they can be placed somewhere else but the installation root. Also unsure where the jre would be placed on MacOS.

Is there a more reliable way to do this?

Context: For our custom update mechanism I need this information to determine the correct mediafile (with or without bundled JRE).

Upvotes: 2

Views: 157

Answers (1)

Reto H&#246;hener
Reto H&#246;hener

Reputation: 5808

Found more info on the help page for JRE bundles:

enter image description here

So my next attempt would be:

String javaHome = System.getProperty("java.home");
String installDir = (String) com.install4j.api.launcher.Variables
    .getInstallerVariable(InstallerVariables.VARIABLE_INSTALLATION_DIR);
String contentDir = (String) com.install4j.api.launcher.Variables
    .getInstallerVariable(InstallerVariables.VARIABLE_CONTENT_DIR);

javaHome = new File(javaHome).getCanonicalPath();
installDir = new File(installDir).getCanonicalPath();
contentDir = new File(contentDir).getCanonicalPath();

boolean bundledJre = javaHome.startsWith(installDir) || javaHome.startsWith(contentDir);

Upvotes: 1

Related Questions