1

I need to run a Java JAR Swing GUI executable in a Raspbian Wheezy Debian distribution inside an ARM device during boot time.

I am following this as reference with myapp,myapp-start.sh and myapp-stop.sh, and this with possible solutions (and others more quite similar). But here is not reference to the DISPLAY variable.

Ive checked a lot of alternatives, with

Tried and not applicable Options:

  • /usr/bin/java -jar -Djava.awt.headless=true $myapp.jar
  • unset DISPLAY (inside myapp-start.sh, above the java -jar sentence)

Errors:

  • java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.

Tried Options (inside myapp-start.sh, above the java -jar sentence):

  • export DISPLAY=:0
  • export DISPLAY=:0.0
  • export DISPLAY=localhost:0.0

Errors:

  • Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable...
  • Client is not authorized to connect to ServerException in thread stack...

Untried Options

  • ssh - X localhost: How should i do an ssh to the X11 server? Where should i execute that under an init.d process?. Is that the standard solution for running a Java program with GUI?.
  • USER=root inside myapp-start.sh: The init.d stops, and request password. So smart, the process don`t start.
  • Should any of the options above to be included in another place than the myapp-start.sh code? Where?

Should not be simpler to run a single piece of code at startup?.

Any other option, will be appreciated.

EDIT 2015-04-12

New Options

In the following options, i am adding a code inside this location /etc/xdg/lxsession/LXDE-pi/autostart for execution after the default user pi logs and X11 starts (see jlliagre suggestion):

  • usr/bin/java -jar /home/pi/Embedded/bin/PowerBar.jar (no ampersand)
  • export DISPLAY=:0.0 usr/bin/java -jar /home/pi/Embedded/bin/PowerBar.jar (no ampersand)
  • /bin/bash /home/pi/Embedded/bin/powerbarstart.sh (no ampersand)

All them start the application in the background, that is, the background music is played, and the graphics are available only through a VNC at :0 (using TightVNC). As side effect, the screensaver activates, and the application freezes, each 60 seconds approx. Please note this same location is also used to disable the screensaver.

Is there a missing option, or symbol, I am not including?.

Solution The device was configured as :1.0 instead of :0.0. Changing this on the myapp-start.sh solved the issue.

3

If your application is not interactive, you might launch a virtual X11 server and set the DISPLAY variable for your application to use it.

Possible X11 servers that can be used that way are:

The latter allows you to connect later to see and interact with the screen with a VNC client (vncviewer).

If you Raspberry pi (or similar) is configured to autologin the pi user under a graphical environment, you can start your application as the pi user and use the :0 display. Beware that you have to make sure X11 has completed its startup before doing it.

Edit: It looks like your configuration is launching a Xvnc server first as the pi user then is launching the frame buffer main X server as the root user. In that case, as you figured out, your application has to be started as root and using :1 as its display.

Alternatively, if what you really want is not to start your application once at boot time but whenever a user (typically pi) logs in under a graphic environment, add it to the rc file applicable to this graphic environment. For example /etc/xdg/lxsession/LXDE-pi/autostart.

  • Check the edited notes. The app is indeed interactive, with some few menus. Under your last suggestion the app starts, but on the background. Regarding your middle suggestion -start the app under the user pi and using :0 after startup-, i actually only have your alternative code...... – Brethlosze Apr 12 '15 at 19:09
  • It is unclear what your configuration is. What device is this? What is its wideo port connected to? What are you seeing on the screen? What user account is logged in? If you open a terminal, what says id and echo $DISPLAY? – jlliagre Apr 12 '15 at 19:22
  • id: uid=0(root) gid=0(root) groups=0(root),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(netdev),999(input),1002(spi),1003(gpio) echo $DISPLAY :1.0 – Brethlosze Apr 12 '15 at 19:29
  • The device is a Raspberry Pi with a single monitor plugged into it. – Brethlosze Apr 12 '15 at 19:30
  • Is it running in console mode or graphic mode? – jlliagre Apr 12 '15 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.