6

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 ?

srilakshmikanthanp
  • 2,231
  • 1
  • 8
  • 25
  • As far as I know jpackage does not provide such an option. – anko Sep 26 '21 at 14:43
  • Thanks for your reply, there is any other option to achive this ? – srilakshmikanthanp Sep 26 '21 at 14:46
  • I think not, but maybe someone else knows. Good luck :) – anko Sep 26 '21 at 14:52
  • 1
    You may want to submit a feature request for this, assuming one doesn't already exist. A potential workaround, if you continue to use `jpackage`, might be to try and do this within your application when it first starts. For instance, on Windows I'm pretty sure startup apps are determined by simply having a shortcut in a specific folder; not sure about other operating systems. – Slaw Sep 26 '21 at 20:45
  • 4
    `jpackage` relies on the wix toolset to build Windows installers. Wix can define [services](https://wixtoolset.org/documentation/manual/v3/howtos/general/install_windows_service.html), or [add a program to start on boot](https://stackoverflow.com/questions/28305179/how-to-making-a-program-start-on-windows-startup-with-wix-toolset). It may be possible to customize your build to specify the options you wish so Wix will build the installer you want, but I haven’t enough `jpackage` experience to know that for sure or provide instructions. – jewelsea Sep 27 '21 at 03:06

1 Answers1

0

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?

Queeg
  • 7,748
  • 1
  • 16
  • 42