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,633
  • Hi, I've run this program from a Linux Mint (with desktop env of course) since a long time and I'm sure that this need NO user interaction when launched from console.I'm asking here not be receive consulence on the software but how to , for example, "declared the display variable'. Please explain me how and where... I'll try. If this fails I'll retry with Xvfb. – realtebo Jul 07 '16 at 07:10
  • Editted to add reference about the DISPLAY variable. I still think xvfb is a better solution - your use case is actually listed in the Wiki article for it – Little Jawa Jul 07 '16 at 07:50
  • Sorry but I got: Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable. – realtebo Jul 07 '16 at 08:00
  • Well... I said you'd probably have issues with it :-( In general, X doesn't accept anybody to connect to it. If your X server doesn't run, or if nobody logged in, you may not get permission to use it. That's why the Xvfb solution is prefferred - you can start it manually from the console, before starting any program. – Little Jawa Jul 07 '16 at 08:08
  • From your edit in the initial question: your server is running, and active on "display 0". This means that what I wrote should work... but you'll need to log into the X server to have it accept processes you create to display anything on it. Since you don't have an actual display, it's not gonna fly :-( The solution is not about the DISPLAY variable, but about Xvfb. Did you try it? – Little Jawa Jul 08 '16 at 12:02