$ sudo vi /etc/systemd/system/demo.service
[Unit]
Description = a demo service
After = network.target
[Service]
ExecStart = /home/ubuntu/scripts/demo.sh
[Install]
WantedBy = multi-user.target
$ cd
$ mkdir scripts
$ sudo vi /scripts/demo.sh
#!/bin/bash
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.
$ sudo chmod +x demo.sh
$ sudo systemctl enable demo.service
$ sudo systemctl start demo.service
$ sudo reboot