ApplicationLauncher (install4j API)
Description: declaration: package: com.install4j.api.launcher, class: ApplicationLauncher

# Class ApplicationLauncher

java.lang.Object
com.install4j.api.launcher.ApplicationLauncher

public class ApplicationLauncher extends Object
This class allows you to launch an installer application, such as an updater, from your own application. It includes a mechanism for the installer application to shut down the invoking application with a "Shutdown calling launcher" action.

In order to use this class, please include `resource/i4jruntime.jar` from your install4j installation into your class path. You do not need to distribute this file along with your application, install4j will do this automatically for you.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `ApplicationLauncher.Callback`
  You can implement this interface to receive notifications when the installer application exits or needs to shut down your application.
  `static interface`
  `ApplicationLauncher.ProgressListener`
  You can implement this interface to receive progress information from the installer application.
  `static class`
  `ApplicationLauncher.ProgressListenerAdapter`
  Empty implementation of `ApplicationLauncher.ProgressListener`.
  `static enum`
  `ApplicationLauncher.WindowMode`
  Window mode for starting the application in process.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ApplicationLauncher()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `isNewArchiveInstallation()`
  Determine if this is a new archive installation.
  `static void`
  `launchApplication(String applicationId, String[] arguments, boolean blocking, ApplicationLauncher.Callback callback)`
  Launch an installer application that you have defined in the install4j IDE.
  `static void`
  `launchApplicationInProcess(String applicationId, String[] arguments, ApplicationLauncher.Callback callback, ApplicationLauncher.WindowMode windowMode, Window parentWindow)`
  Launch an installer application that you have defined in the install4j IDE.
  `static boolean`
  `waitForInProcessApplication(long timeout, TimeUnit unit)`
  Causes the current thread to wait until the currently running in process installer application has been finished.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ApplicationLauncher

    public ApplicationLauncher()

- ## Method Details

  - ### launchApplication

    public static void launchApplication(String applicationId, String[] arguments, boolean blocking, ApplicationLauncher.Callback callback) throws IOException
    Launch an installer application that you have defined in the install4j IDE. The application is launched in a new JVM.
    Parameters:
      `applicationId` - the ID of the installer application to be launched. You can show the IDs of all installer applications on the "Installer->Screens &actions" tab with the "Show IDs" tool bar button.
      `arguments` - the arguments you want to pass to the installer application. Can be `null` if no arguments should be passed. Arguments like `-Dkey=value` will be passed as JVM parameters, just like when calling the installer application from the command line.
      `blocking` - if this call should block until the installer application exits.
      `callback` - an optional call back for receiving notifications when the installer application exits or when the installer application shuts down this JVM. Can be `null`
    Throws:
      `IOException` - if there was an error starting the installer application

  - ### launchApplicationInProcess

    public static void launchApplicationInProcess(String applicationId, String[] arguments, ApplicationLauncher.Callback callback, ApplicationLauncher.WindowMode windowMode, Window parentWindow)
    Launch an installer application that you have defined in the install4j IDE. The application is launched in the same process. The look and feel as well as the locale is not changed. This call will return immediately if you call it from the event dispatch thread (EDT), otherwise it will block until the installer application exits.

    The "Shutdown calling launcher" action has a different effect than usual: The whole process will be terminated when the installer application exits. Furthermore, the "Request privileges" action only works for elevating a helper process, not the main process.

    When using JavaFX in your application on macOS, make sure to pass the system property `-Djavafx.embed.singleThread=true` to your launcher, otherwise the native event loops of JavaFX and the AWT may lead to a deadlock.

    Parameters:
      `applicationId` - the ID of the installer application to be launched. You can show the IDs of all installer applications on the "Installer->Screens &actions" tab with the "Show IDs" tool bar button.
      `arguments` - the arguments you want to pass to the installer application. Can be `null` if no arguments should be passed. Arguments like `-Dkey=value` will be passed as JVM parameters, just like when calling the installer application from the command line.
      `callback` - an optional call back for receiving notifications when the installer application exits or when the installer application shuts down this JVM. Can be `null`
      `windowMode` - if the wizard should be shown in a dialog or in a frame
      `parentWindow` - the parent window if the wizard should be shown in a dialog. Can be `null`.
    Throws:
      `IllegalStateException` - if another in-process installer application is currently running

  - ### waitForInProcessApplication

    public static boolean waitForInProcessApplication(long timeout, TimeUnit unit) throws InterruptedException
    Causes the current thread to wait until the currently running in process installer application has been finished. If no installer application is running, the method returns immediately.
    Parameters:
      `timeout` - the maximum time to wait
      `unit` - the time unit of the `timeout` argument
    Returns:
      `true` if the application has terminated, or no installer application was running and `false` if the waiting time elapsed before the count reached zero
    Throws:
      `InterruptedException` - if the current thread is interrupted while waiting

  - ### isNewArchiveInstallation

    public static boolean isNewArchiveInstallation()
    Determine if this is a new archive installation. An archive installation is defined by a unique build ID and an installation location. If this method hasn't been called before for this archive installation it will return `true` during the lifetime of the current process and set the "new" state to `false` for all future calls from other processes.

    The state is stored as a user setting, so the installation will appear as "new" again if a launcher is executed with a different user account. For initialization of global state, additional custom checks are necessary.

    When an installer was used this method will always return `false`.

    Returns:
      `true` if this is a new archive installation