让 Install4j 安装程序显示 --version 信息

Have Install4j installer display --version info

我使用 install4j 创建了一组安装程序,并且想要一种快速检查安装程序可执行文件版本信息的方法

传统上,这将涉及调用类似 installer-name.sh --version

的内容

理想情况下,这无需解压捆绑的 JRE 即可工作,但我注意到即使 -h 对 install4j 安装程序的帮助也会解压 JRE,所以我假设这不是一个选项...

我想知道的是:

==============

要明确我最后一点的意思是我想要一个解决方案(将 install4j 安装操作构建为 Java 函数):

if(versionRequested){
  printVersion();
  return;
}
//all the rest of my installation actions

而不是:

if(versionRequested){
  printVersion();
}
else{
  //all the rest of my installation actions
}

在安装程序的 "Startup" 节点中,使用脚本

添加 "Run script" 操作
if (Arrays.asList(context.getExtraCommandLineArguments()).contains("--version")) {
    System.out.println("Version " + context.getCompilerVariable("sys.version"));
    context.finish(0);
}
return true;

在 Windows 上,System.out.println 不会打印到控制台,因为安装程序是一个 GUI 应用程序,因此您必须调用

Util.showMessage("Version " + context.getCompilerVariable("sys.version"));

在控制台模式下也能正常运行。