'How to add a program to startup with jpackage?

i am recently looked at jpackage there is any option automatically adds the appilication to startup, For Example consider I have,

App.java

package org.openjfx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * JavaFX App
 */
public class App extends Application {

    @Override
    public void start(Stage stage) {
        var label = new Label("Hello, JavaFX");
        var scene = new Scene(new StackPane(label), 640, 480);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

module-info.java

module Sample {
    requires javafx.controls;
    opens org.openjfx;
}

Using maven to generate runtime,

mvn javafx:jlink

Then generate the installer,

jpackage --win-dir-chooser --runtime-image ./target/image/ --name Sample-Javafx --module Sample/org.openjfx.App -d ./target/bin/

This all works fine but what i want is to register App.java at startup and start this app after installation is it possible with jpackage or there is any trick inside App.java to achive this ?



Solution 1:[1]

While you are running on Windows, I know how to tackle this on Linux.

JPackage will create a Debian Package. Such a package contains mainly two tar balls: The main one contains the files that need to be installed in the filesystem. The other one contains metadata (what package do we have here?) as well as four scripts, each of them will be run at a specific event:

  • preinst executed before the tar ball gets extracted (installation)
  • postinst executed after the tar ball got extracted (installation)
  • prerm executed before the application will be removed (uninstall)
  • postrm executed before the application was removed (uninstall)

Coming back to your question, all I'd have to do is provide my version of the postinst script that would register the application to autostart following https://docs.oracle.com/en/java/javase/17/jpackage/override-jpackage-resources.html#GUID-1B718F8B-B68D-4D46-B1DB-003D7729AAB6

Maybe there is something similar for the Windows version?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hiran Chaudhuri