Configuring your jar file as a service on the linux instance
1. create a unit file located in /etc/systemd/system
$ sudo vi /etc/systemd/system/demo.service
2. add thees lines to the file
3 . create a directory named 'scripts' in the main root
Description = a demo service
After = network.target
ExecStart = /home/ubuntu/scripts/demo.sh
WantedBy = multi-user.target
$ mkdir scripts
4. create a file demo.sh using vim
$ sudo vi /scripts/demo.sh
5. add the next lines to the file assuming your demo.jar file is located in the/home/ubuntu directory .
sudo java -jar /home/ubuntu/demo.jar
insert ( by clicking the 'i' key) and add the following changes.
click the 'esc' key and then ':wq' saving the changes to the file.
6.make the script executable
$ sudo chmod +x demo.sh
7. back to your main dir and enable the service by
$ sudo systemctl enable demo.service
8. start your service
$ sudo systemctl start demo.service
9. reboot and check if the service is on
$ sudo reboot
10. babam !!
now everthing is complete … you are ready to do great things !!!