1
votes

I create a set of installers with install4j, and would like a quick way to check the version info of the installer executable

Traditionally, this would involve calling something like installer-name.sh --version

Ideally, this would work without needing to unpack the bundled JRE, but I notice that even the -h help for install4j installers unpacks the JRE, so I am assuming that is not an option...

What I'd like to know is:

  • Is there any way to specify options like -h, which do one task (like print version info), and then exit gracefully
  • Alternatively, if I will need to parse out this option myself using context.getExtraCommandLineArguments(), is there a way to successfully exit an installation after a certain action runs, without needing to force a "Quit on failure".
    • I'd like to avoid a situation where I have one action which handles a --version and then the rest of my installation in a conditional group.

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

To be clear what I mean by the last point is that I would like a solution like (framing install4j installation actions as a Java function):

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

rather than:

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

1 Answers

1
votes

In the "Startup" node of the installer, add a "Run script" action with the script

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

On Windows, System.out.println will not print to the console, because the installer is a GUI application, so you would have to call

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

which also behaves correctly in console mode.