0

I setup the remote debugging in NetBeans IDE between 2 Linux systems. Remote debugging an application that does not have a GUI works ok, but I am getting this error when I try to remote debug an application that has swing GUI:

Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.

I would appreciate any suggestion!

NetBeans output window:

ant -f /home/toma/NetBeansProjects/GUIFormExamples -Dremote.platform.password=***** -Dremote.platform.rp.target=linux-15 -Dremote.platform.java.spec.ver=17 -Dremote.platform.rp.filename=linux -Ddebug.class=Antenna -Dnb.internal.action.name=debug debug-remote init: Deleting: /home/toma/NetBeansProjects/GUIFormExamples/build/built-jar.properties deps-jar: Updating property file: /home/toma/NetBeansProjects/GUIFormExamples/build/built-jar.properties compile: Copying 1 file to /home/toma/NetBeansProjects/GUIFormExamples/build Copy libraries to /home/toma/NetBeansProjects/GUIFormExamples/dist/lib. To run this application from the command line without Ant, try: java -jar "/home/toma/NetBeansProjects/GUIFormExamples/dist/GUIFormExamples.jar" jar: Connecting to 192.168.1.122:22 Connecting to 192.168.1.122:22 cmd : mkdir -p '/home/toma/NetBeansProjects//GUIFormExamples/dist' Connecting to 192.168.1.122:22 done. profile-rp-calibrate-passwd: Connecting to 192.168.1.122:22 cmd : cd '/home/toma/NetBeansProjects//GUIFormExamples'; '/usr/lib/jvm/j2sdk1.7-oracle/jre/bin/java' -Xdebug -Xrunjdwp:transport=dt_socket,address=localhost:39245 -Dfile.encoding=UTF-8 -jar /home/toma/NetBeansProjects//GUIFormExamples/dist/GUIFormExamples.jar Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207) at java.awt.Window.(Window.java:535)

1
  • The error message tells you that the JVM tries to use an X11 server for graphics, but you haven't told it where to find one. As you are on a Linux system you may want to tell it to use the X11 server running on your development machine - the exact way to configure that is system dependent. Commented Apr 9, 2020 at 18:32

5 Answers 5

2

You need to add DISPLAY environment variable export to your ant build xml file. I have blogged about this issue and it's solution on my blog

For my project there was a target named "-copy-to-remote-platform" and two macros in it: "runwithpasswd" and "runwithkey" in ANT build xml file which required some modifications.

I have added "export DISPLAY=:0;" to last sshexec commands in each of the aforementioned macros so that they both looked like this:

<sshexec host="${remote.platform.host}" port="${remote.platform.port}" username="${remote.platform.user}" password="${remote.platform.password}" trust="true" usepty="true"
                    command="export DISPLAY=:0; cd '${remote.project.dir}'; ${remote.platform.exec.prefix}'${remote.java.executable}' @{additionaljvmargs} -Dfile.encoding=${runtime.encoding} ${run.jvmargs} ${run.jvmargs.ide} -jar ${remote.dist.jar} ${application.args}"/>

Mind the "export DISPLAY=:0;" on the beginning of the "command" attribute.

Sign up to request clarification or add additional context in comments.

3 Comments

please put your solution here.
I have edited my comment to make it more usefull. I wonder if any of those down-voting, marking-for-deletion stackoverflow sheriffs with chests full of oh-I-am-so-important-badges took effort to check whether my solution works ;)
I have updated the link to my blog - it is pointing to the article now
1

You need to use X11 forwarding, to make the GUI on the remote computer visible on your computer (or otherwise give a valid DISPLAY environment variable, so the GUI can be displayed somewhere). This is a Linux configuration issue, Java is just complaining that it can't create a GUI, because (as far as it knows) there is no screen available.

4 Comments

Thank you for your answer! Could you please include more details on how to "to use X11 forwarding, to make the GUI on the remote computer visible"? I am able to do run the program remotely using SSH but I cannot run the program remotely and debug in the same time.
I think that the key to resolve this issue is to be able to run a script before NetBeans starts remote debugging that sets the DISPLAY variable:export DISPLAY=<hostname_to_display_X11_graphics_to>:0.0
You could try setting the DISPLAY in your .bashrc or similar, to see if it works (and then try to think of a cleverer solution). You should format the output, because now it's hard to see what's doing what.
Kayaman, Thanks for your suggestions! It helped me to find the solution and put together the answer below.
1

Success! It is not as easy as it should be, but it works.

In NetBeans (I used version 8) create a new Java Platform for remote debugging: Tools -> Java Platforms -> Add Platform -> Remote Java Standard Edition -> ... (for more info see this link: https://netbeans.org/kb/docs/java/javase-embedded.html). Press the drop-down menu on the Debug Icon (debug-remote) and watch the output window.

That works well if the program does not have a GUI. If the program has a GUI, I get this error: "java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it"

Even if the program has a GUI, the steps above help, because it automatically deploys your program on the remote server.

To debug the GUI, the workaround I found, is to remotely connect to the server using ssh or VNC and run the java program in debug mode:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y -jar "/MyPath/Program.jar".

Java VM should pause the program and wait for NetBeans debugger to connect.

In NetBeans, set a break point in the program and attach to the remote process: Debug -> Attach Debugger -> Java Debugger, SocketAttach, dt_socket, IP address of the server, Port: 4000 -> OK

Later on you can just press the drop-down menu on the Debug Icon (Attach to ...) to start debugging.

The program should run to the break point and pause execution. You should have full control over the GUI on the programming computer but the program is executed on the server.

This is very useful when debugging Java programs on single board computers like BeagleBone Black or Raspberry PI that do not have enough horsepower to run NetBeans. This is essential when the single board computer is used in a robotics application and it needs to receive sensor inputs and control motors.

Comments

1

The Solution:

  1. Go to Run → Set Project Configuration → Customize..
  2. Click Manage Platforms
  3. Select the remote configuration for your RPI
  4. On right sight go to Exec Prefix and write startx in it.

Comments

1

Problem is that NetBeans single-quotes everything that you put into the Exec Prefix field. So you can put in your own single-quotes to construct a valid bash command. Imagine you have a VNC virtual desktop at display :2.0, you can trick it out with export' DISPLAY=:2.0;'sudo Finally this will result in a working bash command string with a quoted export and a quoted sudo (which does no harm). If you don't want your program to run in superuser mode, change it to export' DISPLAY=:2.0;sudo -u 'pi I found only the sudo command as a working way to cope with these single quotes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.