I have an example Java application for testing. It uses the Java Swing library. I try running it with xserver in the Linux shell, so I'm not using a desktop environment.
Usually, you can run e.g. Firefox without problems like this:
startx /usr/bin/firefox
I tried exporting DISPLAY and running the application headless, but it only printed the first of the following lines.
{
System.out.println("This works");
JOptionPane.showMessageDialog(null, "This should show up");
}
If I run java -jar app.jar from the command line, I get a following error message:
Exception in thread "main" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
With startx java -jar app.jar, the output is:
Bad command line option "-jar"
This should be:
startx /usr/bin/java -jar app.jar —-
Refer to https://askubuntu.com/questions/697978/how-to-pass-a-program-and-its-arguments-to-start or the startx manual page.
Edit: updated based on @chief654’s response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With