简体   繁体   中英

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, eg

<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).

Found more info on the help page for JRE bundles :

在此处输入图像描述

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM