简体   繁体   中英

How to programmatically install a jar file to startup on all operating systems - Java

So i have come across a problem with installing my java application to startup on all Operating Systems.

Firstly I know this is possible on Windows by adding a new key to registry (I think).

I believe the command: 'reg add' works on windows.

I'm not 100% sure about Mac but i believe you can use a service wrapper?

And for Linux I have no clue.

Basically i want my application to be installed to startup when a user ticks a box, no matter which operating system it is run on.

Just some clarification on these and if possible an example for each would really assist me. Any help with this is greatly appreciated. Thanks.

Add a .desktop file to one of the following directories:

  • $XDG_CONFIG_DIRS/autostart/ ( /etc/xdg/autostart/ by default) for all users
  • $XDG_CONFIG_HOME/autostart/ ( ~/.config/autostart/ by default) for a particular user

See the FreeDesktop.org Desktop Application Autostart Specification for details.

So for example,

    PrintWriter out = new PrintWriter(new FileWriter(
        System.getProperty("user.home")+"/.config/autostart/myapp.desktop"));
    out.println("[Desktop Entry]");
    out.println("Name=myapp");
    out.println("Comment=Autostart entry for myapp");
    out.println("Exec=" + installPath + "/bin/myapp_wrapper.sh");
    out.println("Icon=" + installPath + "/myapp_icon.png");
    out.flush();
    out.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM