B4J Question Pi3 JavaFX and Display Problem

rdkartono

Member
Licensed User
Longtime User
I installed LibericaJDK 11 , version 11.0.5 :
B4X:
openjdk version "11.0.5-BellSoft" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5-BellSoft+11)
OpenJDK 32-Bit Server VM (build 11.0.5-BellSoft+11, mixed mode)

B4J-Bridge version is 1.43.

Raspbian version is
B4X:
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

I found problem on connecting PC app to Pi3 using B4J-bridge.
I ran B4J-bridge using sudo java -jar b4j-bridge.jar, and error message will be java.lang.UnsupportedOperationException: Unable to open DISPLAY
B4X:
Exception in thread "main"
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:173)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:171)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
    at javafx.graphics/com.sun.glass.ui.Application.run(Application.java:144)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:258)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    ... 5 more

If I ran B4J-bridge without sudo, just java -jar b4j-bridge.jar, application also can not run, with the same message.

Later I read on Internet, that we can use DISPLAY=:0 java -jar b4j-bridge.jar, then this can run.

However, since I will be using GPIO, I2C and etc , i need sudo, but if I ran sudo DISPLAY=:0 java -jar b4j-bridge.jar, above error will come out.

Please advice if anybody have tried and have solution.
 

rdkartono

Member
Licensed User
Longtime User
I think it is not because RP's Video Ram, since I can run app , but without sudo and must include DISPLAY=:0.
I need sudo for low access
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Ha, learned something new!
Looks like using sudo resets all environment variables, which includes DISPLAY (link #1). In order to prevent this, you'll have to edit the /etc/sudoers file and add, at minimum
Defaults env_keep+="DISPLAY"
One poster (link #2) did
Defaults env_keep="XAUTHORIZATION XAUTHORITY TZ PS2 PS1 PATH LS_COLORS KRB5CCNAME HOSTNAME HOME DISPLAY COLORS"
but that may be total overkill (someone else questions the inclusion of HOME).

Another post (link #3) seems to suggest that DISPLAY and XAUTHORITY are the two requirements. You may need to modify your .bashrc file in order to XAUTHORITY to be handled properly.

You can use
to see what environment variables will be kept by sudo. Let us know what works.

Links:
#1) https://askubuntu.com/questions/135...-run-an-app-with-sudo-or-gksudo/137584#137584
#2) https://askubuntu.com/questions/414785/cant-open-gedit-as-root
#3) https://unix.stackexchange.com/ques...-run-gui-apps-from-root-no-protocol-specified
 
Upvote 0

rdkartono

Member
Licensed User
Longtime User
This is not solving :
Looks like using sudo resets all environment variables, which includes DISPLAY (link #1). In order to prevent this, you'll have to edit the /etc/sudoers file and add, at minimum
Defaults env_keep+="DISPLAY"

This one :
Defaults env_keep="XAUTHORIZATION XAUTHORITY TZ PS2 PS1 PATH LS_COLORS KRB5CCNAME HOSTNAME HOME DISPLAY COLORS"
and execute with
DISPLAY=:0 sudo java -jar b4j-bridge.jar
can run the app.

sudo -V content is
sudo -V
Sudo version 1.8.27
Sudoers policy plugin version 1.8.27
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.27

However I will test again.
 
Upvote 0
Top