Thanks Raedwald. I studied the post you mentioned and I finally resolved it.

Here the steps I did.

startapp.sh

#!/bin/bash
java -jar /home/usr/local/bin/vedioplayer.jar

created the above script and saved it in /etc/init.d make sure you allow execution of the shell script.

  sudo chmod +x /etc/init.d/startapp.sh

After that run the follwing command

  sudo update-rc.d startapp.sh defaults 98 02

Also you can add the script to Startup Applications list from Applications.

Answer from Rajith Pemabandu on Stack Overflow
Discussions

shell script - Executing .jar File on Startup - Unix & Linux Stack Exchange
I'm running a Nukkit Minecraft server on my Raspberry Pi (I know it doesn't have good hardware but I'm experimenting) and googling different ways to make a bash file for Linux. I have made the file More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
November 11, 2017
ubuntu - Make a "java -jar file.jar" run at startup - Unix & Linux Stack Exchange
Hello I am running a kubuntu 13.10 distro, but I guess my question is pretty general...how to make a .jar execute in background at system start? More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
April 8, 2014
How to run a JAR file on startup? (Ubuntu 13.10)
i think ubuntu still uses /etc/init.d/ all you have to do is put a symlink to the file you want to execute in /etc/init.d/ since you are running a JAR file and need some arguments, i would suggest writing a VERY simple bash script that only launches your jar. inside your bash script would be something like #!/bin/sh java -jar /absolute/path/to/jar/myJAR.jar now save that script to a file, mark it as executable and put it(or a link to it) in your /etc/init.d/ now your bash script will launch at boot to launch your jar. More on reddit.com
๐ŸŒ r/Ubuntu
7
2
September 19, 2013
bash - run jar-file on startup linux - Stack Overflow
I've used a standard bash-startup script for autostarting my Teamspeak Server - which works perfectly. Now I've done the same for the JTS3 Server Mod, problem: It's a .jar-file and doesn't start. I... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Top answer
1 of 7
34

Here's a easy way to do that using SysVInit. Instructions:

  1. Create the start and the stop script of your application. Put it on some directory, in our example is:

    • Start Script: /usr/local/bin/myapp-start.sh
    • Stop Script: /usr/local/bin/myapp-stop.sh

    Each one will provide the instructions to run/stop the app. For instance the myapp-start.sh content can be as simple as the following:

    #!/bin/bash
    
    java -jar myapp.jar 
    

    For the stop script it can be something like this:

    #!/bin/bash
    # Grabs and kill a process from the pidlist that has the word myapp
    
    pid=`ps aux | grep myapp | awk '{print $2}'`
    kill -9 $pid
    
  2. Create the following script (myscript) and put it on /etc/init.d.

    /etc/init.d/myscript content:

    #!/bin/bash
    # MyApp
    #
    # description: bla bla
    
    case $1 in
        start)
            /bin/bash /usr/local/bin/myapp-start.sh
        ;;
        stop)
            /bin/bash /usr/local/bin/myapp-stop.sh
        ;;
        restart)
            /bin/bash /usr/local/bin/myapp-stop.sh
            /bin/bash /usr/local/bin/myapp-start.sh
        ;;
    esac
    exit 0
    
  3. Put the script to start with the system (using SysV). Just run the following command (as root):

    update-rc.d myscript defaults 
    

PS: I know that Upstart is great and bla bla, but I preffer the old SysV init system.

2 of 7
6

Yes! It is possible. :) Upstart is the way to go to make sure the service stays running. It has five packages, all installed by default:

  • Upstart init daemon and initctl utility
  • upstart-logd provides the logd daemon and job definition file for logd service
  • upstart-compat-sysv provides job definition files for the rc tasks and the reboot, runlevel, shutdown, and telinit tools that provide compatibility with SysVinit
  • startup-tasks provides job definition files for system startup tasks
  • system-services provides job definition files for tty services

The learning is very enjoyable and well worth it. Upstart has a website: http://upstart.ubuntu.com/

๐ŸŒ
Linux.org
linux.org โ€บ home โ€บ forums โ€บ general linux forums โ€บ general linux topics
execute .jar file on system start. | Linux.org
November 11, 2020 - actually what I want to run is a bash file, (netbeans was just for testing). This is the bash file: #! / bin / bash export JAVA_HOME = / usr / lib / jvm / jdk1.8.0_261 java -jar /home/luilli/Desktop/dist/table.jar and this is the crontab command: 32 12 * * * /home/luilli/firstboot.sh has permissions to run, change them with: chmod 744 firstboot.sh i tryed to run the bash file directly from the terminal , and it runs perfect.
๐ŸŒ
Reddit
reddit.com โ€บ r/ubuntu โ€บ how to run a jar file on startup? (ubuntu 13.10)
r/Ubuntu on Reddit: How to run a JAR file on startup? (Ubuntu 13.10)
September 19, 2013 -

I use RemoteDroid, which allows you to use an Android device for input. (My Ubuntu box is my TV PC). I downloaded the JRE and got the .jar file to execute without issues, but getting it to start on boot is seemingly impossible. (I'm just simply trying to avoid having to plug a keyboard/mouse in just to start the program.)

I've scoured the web finding a myriad of different solutions; some adding additional software, some using UpStart (which I'm not too familiar with), all of which seem to be extremely complex (and obviously not working for me). There's gotta be a simpler way to just run this .jar on startup without a bunch of hacks.

Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 36824970 โ€บ run-jar-file-on-startup-linux
bash - run jar-file on startup linux - Stack Overflow
# Don't change the lines below, if you are not a sh script expert! cd "${BINARYPATH}" BINARYNAME="JTS3ServerMod.jar" ROOTUID="0" case "$1" in java) if which java >/dev/null 2>&1 ; then echo "Java is already installed:" java -version else if [ "$(id -u)" -ne "$ROOTUID" ] ; then echo "Start this script as root to start the automatic installation of the Java runtime environment." echo "You can also read the system requirements of the JTS3ServerMod in the readme.txt file for a manual installation of the Java runtime environment." exit 6 else read -p "Do you wish to install the Java runtime environment?
๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 779830 โ€บ running-an-executable-jar-file-when-the-system-starts
services - Running an executable jar file when the system starts - Ask Ubuntu
Second a jar file is not an executable file to run but you need java to run at startup, so you have to make a script , make it executable or put your commands in your /etc/rc.local file :
๐ŸŒ
GitHub
gist.github.com โ€บ marlonbernardes โ€บ eef26b818270ef3b6d02
How to make a jar file run on startup ยท GitHub
How to make a jar file run on startup. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 941447 โ€บ how-to-make-jar-file-run-automatically-on-system-start
bash - How to make jar file run automatically on system start - Ask Ubuntu
!/bin/bash # AppDemo # # description: Start Jar on system boot case $1 in start) /bin/bash /usr/local/bin/AppDemo-start.sh ;; stop) /bin/bash /usr/local/bin/AppDemo-stop.sh ;; restart) /bin/bash /usr/local/bin/App-Demo.sh /bin/bash /usr/local/bin/App-Demo.sh ;; esac exit 0
๐ŸŒ
LinuxVox
linuxvox.com โ€บ blog โ€บ start-a-jar-file-like-service-in-linux
How to Run a JAR File as a Linux Service: Start, Stop, and Manage with systemd โ€” linuxvox.com
Java applications are often distributed as JAR (Java ARchive) files, which are easy to run with a simple `java -jar` command. However, running a JAR manually has limitations: it stops when you log out, requires manual restarts after crashes, ...
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ how-run-java-jar-application-systemd-linux-service-dhaval-gajjar
How to run java jar application with systemd on Linux as service
December 14, 2022 - [Unit] Description=Email service ... WantedBy=multi-user.target ยท You can change the user to the system user you want to run the application with and change the java path....
Top answer
1 of 2
4

Regrettably, I don't believe there is a single, universal way to accomplish exactly what you want. Each nix has an init system, and there are various different init systems out there (SysV, Upstart, systemd, etc.). Now, systemd has some support for running SysV daemons, so you might be able to get away with writing a SysV script and have it work for both, but I do not know how that will fare with Upstart and other systems. I can see two courses of action that may yet help you accomplish your goal:

  1. Write a service for each major init system (note that many distros are switching to systemd, so it may be a good one to start with).

  2. Give up on running it at boot and try to run it a little later.

For example, though init systems are still pretty fragmented, shell login is pretty much universal. You could add a couple lines to each $HOME/.shellrc running the jar if it hasn't already been run. Doing so would be much less work and much more universally applicable.

The obvious advantage of 1 is that it would run the jar before users see anything. However, this can be mitigated in 2 by setting up autologin (though not a great idea for security).

Note that, if this is a GUI jar, then you're going to have a fair number of extra headaches (making X, or Wayland start so that your jar can run will add a few lines, at least, to whatever solution you decide).

2 of 2
2

There is no universal method for creating a system service on all GNU/Linux distros, since they use a variety of init systems. Once upon a time they all used more or less the same SysV style init (excepting some which used a more BSD style system), which allowed for the writing of generic init scripts that would require little modification from distro to distro.

Currently, SysV is still used by a number of distros, such as Debian and RHEL / CentOS. However, the newer init systems -- systemd (Fedora, Arch, et. al.) and upstart (Ubuntu)1 do include mechanisms for backward support of SysV style init scrips, so if you are looking for the method most easily adopted for use on the most systems, that is still it.

Keep in mind that "linux" is not an operating system in the sense that "Windows 8" or "OSX" are operating systems. Linux is an OS kernel used on a wide variety of platforms (e.g., Android); colloquially "GNU/Linux" refers to the collection of OS distributions discussed above, but these are not all the same. There is no serious intention or desire to unify these, just as there is no serious intention or desire to unify Windows and OSX so that, e.g., someone could ask "How can I run my jar file at start up on both OSX and Windows?" -- you are out of luck, you will need to package it separately for each of them. That is, in fact, how software in the linux world generally is distributed; there are separate packages for each and every distro.

1 BUT Ubuntu (and Debian) are moving to systemd, meaning upstart will likely disappear, and most of the major distros will have a common init system.

๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 947344 โ€บ how-to-run-a-jar-application-as-a-service-start-on-boot-of-system
systemd - How to run a .jar application as a service (Start on boot of system) - Ask Ubuntu
August 18, 2017 - Show us how your systemd service looked like. ... i) Create your bash script called mystartup.sh to run the .jar file in /etc/init.d/ directory(login as root)