javainstall4j

How can I get the version of the currently executing launcher?


My current attempt is:

File executionDir = new File("").getCanonicalFile();
ApplicationInfo info = ApplicationRegistry.getApplicationInfoByDir(executionDir);
return info.getVersion();

It works, but I wonder if there is a way to get at the information without making any assumptions about the current working directory?


Solution

  • You can query the sys.version compiler variable:

    import com.install4j.api.launcher.Variables;
    
    try {
        String version = Variables.getCompilerVariable("sys.version");
    } catch (IOException e) {
        // TODO not running in installation
    }