2

I'm building a spring based javafx application which is aimed to run both on Linux and Windows machines.

I've encountered an error, and couldn't find a satisfying solution to the problem.
While trying to run the command sudo java -jar MS.jar, I'm getting InvocationTargetException:
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY

Of course, while executing java -jar MS.jar alone, everything works great.

BTW, Running echo $DISPLAY in terminal results with ":0"

The software is a javafx UI software, which needs sudo privileges for kernel tasks.

Machine details:
OS: OpenSuse 42.1
JAVA version: "1.8.0_152"

How can I resolve this issue?

Thanks!

nafarkash
  • 359
  • 6
  • 24

2 Answers2

3

Have you tried any of gtksudo/gtksu/kdesu

commands instead of sudo?

If your app is a UI app that should do the trick.

For more info see : https://linux.die.net/man/1/kdesu , http://www.linfo.org/kdesu.html

roeibit
  • 46
  • 4
1

Quoting an answer from elsewhere that worked for me with javafx as root on Ubuntu ... Maybe this can help someone else. I had the same question as you but for a normal user. Let's say I want to start firefox using the user account foo. I'm logged in as bar:

[bar@localhost ~]$ sudo -u foo -H firefox

Sadly that command failed with the same error as in the question (i.e. no protocol specified & cannot open display)

My solution was to simply add the user foo to the list of authorised access to the X server.

xhost si:localuser:foo

And that was it, I was then able to launch Firefox (and other X application) using sudo and the user foo.

Howard J
  • 421
  • 3
  • 7