Autostart JavaFX Application on RaspberryPi

2019-06-07 16:51发布

I programmed a JavaFX application which runs on a "Raspberry Pi" (a small ARM based Linux Computer). The OS on the "Pi" is "Raspbian" (a Debian Linux for Raspberry Pi). I installed JDK8 on Raspbian to run graphic JavaFX Application without X-Server. This all works fine :) I can start the Application by entering the following command:

/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte

When the application starts it takes full control over mouse an keyboard, so there is no way back into console, but this doesent maters because it is just a monitoring system an i am able to shut the mashine down over ssh.

I now want to start the application directly after booting, so that there is no need for entering username ,passwort and starting the application.

The mashine does nothing else just running the app (of course there runs a ftp, ssh deamon for making updating the app posible)

Please tell me step by step, because i dont work with Linux for a long time.

Thank you very much.

2条回答
Summer. ? 凉城
2楼-- · 2019-06-07 17:04

CMD

cd /etc/init.d
sudo nano leitwarte

Enter the following

#! /bin/sh
# /etc/init.d/leitwarte

touch /var/lock/leitwarte

case "$1" in
start)
echo "Starting Leitwarte ... "
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte > /dev/null &
;;
stop)
echo "Killing Leitwarte ..."
killall java
;;
*)
echo "Usage: /etc/init.d/leitwarte {start|stop}"
exit 1
;;
esac
exit 0

then

chmod 755 leitwarte
update-rc.d leitwarte defaults

DONE

查看更多
欢心
3楼-- · 2019-06-07 17:14

I solved this problem

When the application starts it takes full control over mouse an keyboard, so there is no way back into console

by adding quotes ("") and by giving -Djavafx.platform=gtk for DEFAULT_JVM_OPTS. For example in my case I replaced this code:

DEFAULT_JVM_OPTS=-XX:+UseG1GC -Dmode=prod_w_updates

to this:

DEFAULT_JVM_OPTS="-XX:+UseG1GC -Dmode=prod_w_updates -Djavafx.platform=gtk"

Hope, it will help

查看更多
登录 后发表回答