execute .jar file on system start.



with an init.d script.
with a systemd script
with a firstboot/cron script

Hopefully you have java installed.
 
NOTE*: You will need root privileges to do this.

cd /root
wget http://somewebserver.com/firstboot.sh
chmod 744 firstboot.sh
echo "@reboot root /bin/bash /root/firstboot.sh" >> /etc/crontab


================ firstboot.sh ============
#!/bin/bash
export JAVA_HOME=/path/to/java
java /path/to/my.jar

# This will delete this cronjob. Don't add this part if you want this every reboot.
/bin/cat /etc/crontab | /bin/grep -v firstboot > /etc/crontab.tmp
/bin/rm -f /etc/crontab
/bin/mv /etc/crontab.tmp /etc/crontab
rm -f $0
====================================

The downside is, you lose any other root cron jobs. There is a way around this.
 
Or you can use a systemd unit file, here's an example.
 
i'm trying to start from the basic, and i try with this with crontab but doesn't work:
57 18 * * * /usr/local/netbeans-8.2rc/bin/netbeans
it should start netbeans at 18:57 but it doesn't. What's wrong?
thanks in atvance.
 
How are you creating the crontab?
You should use "crontab -e" .
What user are you running the crontab as? Does that user have permissions to run netbeans?

*debug*
What happens when you simply run the command in the crontab? Do you get any errors?

Netbeans is a developer IDE, it wants a Xwindows GUI to run in. Is Xwindows running?
Are you logged in as the user the crontab is running as?
 
Since it's netbeans is a graphical IDE sounds more like it should be automatically started in the user session. Depending on what DE you are using it will differ, if you are using Ubuntu's default(Gnome3) DE you can search for "Tweak Tool" in the menu open it and then select the sessions tab or something like that. After which you probably have to click and select the application you automatically want to start after login.
 
Last edited:
You can also probably stick a link to it in ~/.config/autostart in your user profile.

sudo ln -s /path/to/file ~/.config/autostart
 
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.
 

Members online


Top