javawindowsservicejpackageservice-installer

How to create launcher as windows service using jpackage (Java 19)


I want to create an installer with jpackage that registers my java application launcher as a Windows service.

I have installed WiX Toolset v3.11.2.

I have tried to create my installer by specifying the --launcher-as-service flag which is supported in Java 19 JDK-8275062 but I am getting the following error:

> jpackage --type msi -i . --main-jar my-app.jar --name my-app --app-version "1.0.00" --dest . --win-shortcut --win-menu --launcher-as-service
Bundler MSI Installer Package failed because of java.lang.NullPointerException: Cannot invoke "jdk.jpackage.internal.InstallableFile.srcPath()" because "this.serviceInstaller" is null

The documentation mentions a certain service installer executable (service-installer.exe) as a resource to consider. Any idea where I can find this executable and what would be the best thing to do?


Solution

  • I've been able to manage this issue by configuring the --resource-dir option to specify the NSSM resource path, and I have renamed nssm.exe to service-installer.exe.

    > jpackage --type msi -i . --main-jar my-app.jar --name my-app --app-version "1.0.00" --dest . --win-shortcut --win-menu --resource-dir "C:\Program Files\nssm-2.24\win64" --launcher-as-service
    

    Certainly! Here's a draft for your Stack Overflow post update with a redirection to your Medium article:


    Update:

    To manage the service-installer.exe file:

    For a detailed, step-by-step guide on how to create a Windows Service with Java 21, JPackage, and Maven, you can check out an article I wrote here.