I have made a Windows installer for a JavaFX + Spring Boot application using the answer to:
However, the installer just quit after finishing its job without any notification.
My question is: How to make it display a message after successful/failed installation?
This is a Windows only solution.
You need to override the default jpackage WIX resources and customize the installer configuration.
Make sure you read the documentation on overriding jpackage resources before attempting this.
Launch your application after installation is complete
We can't customize the UI of the WIX installer at all (when jpackage from JDK 21 is used), as far as I can tell. The reason why is explained later in the answer.
But, we can customize the WIX installation configuration so that it will launch our application with a custom parameter after installation is complete. And then we can provide our own UI (in JavaFX) to handle the post installation tasks in any way we wish.
To do this, set a resource directory for jpackage, by uncommenting this line from the
jpackage-maven-pluginsection of thepom.xmlin the answer referenced in the question.Set a value for the temp directory that jpackage uses so that it persists after an execution:
Then when jpackage runs, temporary files will be output to the build directory and you can view them there after a build.
Running maven in debug mode and jpackage in verbose mode is pretty much mandatory for developing this solution, as it will display the jpackage commands and the WIX commands in the build output that way, together with any errors that jpackage or WIX detects.
config/jpackage/resources/main.wxs
Create this new file which defines the Wix project configuration that jpackage will use for your application.
The file was created by copying the generated resource file from
target/jpackage-temp/config/main.wxstoconfig/jpackage/resources/main.wxs. And then customizing it to launch the installed application on installation.It will only launch the application if the application has never been installed or is installed and is being upgraded to a new version. If the same version of the application is already installed, the installer won't launch your application because the installer doesn't do anything in that case.
These lines were added to the WIX project file under the
Productsection (wininstalledis the name of the application, you should adjust it fit your application name)And this line was added to the
InstallExecuteSequencesection:What will happen now, is that, after the installation is complete, your application will be launched with a command line parameter
--start-mode=installed.HelloApplication.java
So, now we can modify the code of the application to recognize and act on this parameter. What you choose to do when the parameter is set is up to you. In this example what I do is pop up an alert dialog notifying that the application was installed.
The alert is
setAlwaysOnTop(true)so that it will display on top of other windows. Otherwise, it won't show immediately, instead the application icon will be highlighted by the OS in the windows task bar indicating that the application is running and has UI to show and then the UI can be seen after clicking the app icon in the task bar.In this example, after the user dismisses the installation notification dialog, the main application window is shown, but you could instead quit the application if you wish.
The code queries the startup parameter to see if it was invoked from the installer and only shows an alert in that case. If you start the application normally (for example by double clicking on the application icon on the desktop), then, as expected, no installation alert dialog will be displayed in that case.
This is a modified version of the application code that was generated by the Idea IDE during the steps to create a packaged application that are outlined in the answer referenced in the question.
The WIX Installer UI generated by
jpackageis not customizableOne approach might be to modify the
WIXUI_MinimalDialog set to include anExitDlgthat displays a custom message after the installation is complete.However, unfortunately
jpackagegenerated packaging cannot use the standard WixUI dialog sets. This answer describes how these dialog sets are used:The answer notes that you must have the following switch on the command line to the wix toolkit:
But jpackage does not place this extension on the command line, so customized Wix Installer UI cannot be created for applications built using jpackage. I guess adding support for that might be provided by a feature request. This could be accomplished by adding a switch for custom UI in the jpackage command and, if set, providing the appropriate parameters to the wix tools.
This is an example light command issued by jpackage, it uses the
-ext WixUtilExtension, but not the-ext WixUIExtension: