【问题标题】:How to determine at launcher runtime whether the JRE is bundled locally or not?如何在启动器运行时确定 JRE 是否在本地捆绑?
【发布时间】:2021-12-30 05:38:29
【问题描述】:

我在想也许检查java.home 是否以当前执行路径开头,例如

<install.dir>/jre

但是,启动器可以配置为更改工作目录,或者它们可以放置在安装根目录以外的其他位置。也不确定 jre 在 MacOS 上的位置。

有没有更可靠的方法来做到这一点?

上下文:对于我们的自定义更新机制,我需要此信息来确定正确的媒体文件(有或没有捆绑的 JRE)。

【问题讨论】:

  • 如果您已经有两个分发包,那么为什么不将此配置信息作为部署的一部分添加到包中呢?
  • @ThorbjørnRavnAndersen 是的,这是一个选择。但只要有可能,我宁愿不增加我们的安装程序配置复杂性(已经非常高)。此外,可以手动从安装中删除捆绑的 JRE。而且我们的更新服务器已经期望一个查询参数指定有/没有 JRE,由于前几年的现有安装,我们无法更改。

标签: java install4j


【解决方案1】:

help page for JRE bundles上找到更多信息:

所以我的下一个尝试是:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    • 2014-06-03
    相关资源
    最近更新 更多