1

I'm running a java program that is already able to work from command line, but only if a x server is up and running.

Actually on my ubuntu 16.04 x64 VPS I got this java exception

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

How to fix this?

I tried to

sudo apt-get install ubuntu-desktop

Of course it's useless for me but I thinked it was enough to satisfy the need of an X server ...

What could I do now?

UPDATE:

I tried, after a lot of Googling, to do

root@ziff-01:~# X -configure
(EE)
Fatal server error:
(EE) Server is already active for display 0
        If this server is no longer running, remove /tmp/.X0-lock
        and start again.

So, If X is active, where / how must I configure that "DISPLAY var"?

realtebo
  • 399

1 Answers1

2

Installing ubuntu-desktop is not enough. The problem is that, in this context, the program is run outside of an X server.

You could try to declare the DISPLAY variable before calling it, making it use your (newly installed) X server... but you'll probably have permission issues. This would look like: export DISPLAY=:0.0, which is the default (but is not set when you access the computer from the console).

You can look here for details on what the DISPLAY variable is and how to set it: What is $DISPLAY environment variable

EDIT: from your additional info in the question, it seems your server is actually using "display 0", and then export DISPLAY=:0.0 should work. The reason why it doesn't is probably due to access rights - you need to log into X to be able to display anything on it. That's what I meant when talking about permissions.

Recommended solution

Another (probably better) way to deal with it and that I've used a long time ago, is to use a virtual X server like Xvfb (https://en.wikipedia.org/wiki/Xvfb) It acts as a X server, but performs no operations. Then your application should be happy with it. It's actually one of the use cases listed on the Wikipedia entry for it.

To use it, you need to do the following:

sudo apt-get install xvfb
xvfb-run [your command]

One word of caution though: there may be a reason for your programs to want an X server. It may actually need some level of user interaction through it, and if that is the case, not being able to see what's going on will make the program useless...

I'd recommend looking for information with the program's maker, or other users of this program, rather than the Ubuntu community.

Little Jawa
  • 2,643