Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java application throws `Gtk-WARNING **: cannot open display:` even when xserver is not required

I have a Java application that uses WebRenderer for a java headless browser. WebRenderer does not require xserver to run and I have confirmed this by uninstalling all x11 libs and xserver components.

However the problem is it throws an error: Gtk-WARNING **: cannot open display: in certain conditions. Upon research I found that it usually throws that error with systems that have openJDK installed. Also when the current java version is from Sun but openJDK is still installed. To fix it I would need to uninstall libatk-wrapper-java and libgtk2.0-0 (which also removes default-jre, cedtea-netx, libatk-wrapper-java-jni, libgtk2.0-bin, and openjdk-6-jre).

It also throws the same error in openSUSE (with Java from Sun). Would there be any way to fix this error without having to start up xserver or uninstalling a bunch of components that could be required for something else? Any help is appreciated.

like image 728
KrispyDonuts Avatar asked Nov 13 '22 01:11

KrispyDonuts


1 Answers

Yes, use Xvfb.

In one terminal, you run Xvfb :1. In the other terminal, you run DISPLAY=:1 ./yourapp.

Some distros have a xvfb-run script that does the magic of launching Xvfb and your app on the same command.

http://en.wikipedia.org/wiki/Xvfb

Google for Xvfb for more information

like image 78
pzanoni Avatar answered Dec 27 '22 06:12

pzanoni