Search code examples
javacloud9-idevnc

How do I get Cloud9 and noVNC to work so that JOptionPane is visible?


I had this previous question and ended up talking to C9 support, which helped me make some progress. To reiterate, the issue was running a simple Java program with JOptionPane:

import javax.swing.JOptionPane;

public class Test
{ 
  public static void main ( String args[] ) 
  { 
    JOptionPane.showMessageDialog (null, "This is a sample program" ); 
  } 
}

Resulted in these errors:

Exception in thread "main" 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.<init>(Window.java:535)                                                                                                          
  at java.awt.Frame.<init>(Frame.java:420)                                                                                                            
  at java.awt.Frame.<init>(Frame.java:385)                                                                                                            
  at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1756)                                                                     
  at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1831)                                                                         
  at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1697)                                                                                      
  at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:863)                                                                                   
  at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:667)                                                                                  
  at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:638)                                                                                  
  at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:609)                                                                                  
  at Test.main(Test.java:8)

Obviously there is no GPU or monitor, so it needs to be emulated. I was given the following steps:

First, to set parameters:

sudo apt-get install xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable x11-apps

Second, to make display available and give it the number 99:

Xvfb :99 -ac -screen 0 1280x1024x16 & 

Third, create a x11vnc password:

x11vnc -storepasswd s3cr3t3 ~/.vnc/passwd

Fourth, start the VNC server.

sudo x11vnc -rfbauth ~/.vnc/passwd -xkb -noxrecord -noxfixes -noxdamage -ncache 10 -rfbport 5900 -display :99 &

Fifth, this causes it to listen on port 5900, but only 8080 is available, so noVNC is needed:

git clone git://github.com/kanaka/noVNC

Sixth, run noVNC:

./noVNC/utils/launch.sh --vnc localhost:5900

I don't run into issues until I try to use my browser to connect to noVNC. There seems to be three was to do this:

This was given to me by C9 support:

https://<workspace>-<username>.c9.io/vnc.html

This is what noVNC generates to point browser to:

http://<username>-<workspace>-1260462:6080/vnc.html?host=<username>-<workspace>-1260462&port=6080

Then there is also this website where can specify host, port, passwords, etc.

http://kanaka.github.io/noVNC/noVNC/vnc.html

At any rate, I can never connect and I am not sure what I am doing wrong. I have verified all the steps up to starting noVNC have initialized correctly and are currently running. I have read pretty much all the documentation on it. Running this on Windows 7 with the latest Chrome.

Regards


Solution

  • I don't have this completely working but I might be a single small step closer than you. Your steps were really helpful to me. I can start X11 applications but not interact with them. I can only see the initial screen.

    You need to modify the line where you start the noVNC server:

    ./noVNC/utils/launch.sh --vnc localhost:5900 --listen 8080 &

    You can then access the noVNC web service on the following url from your normal browser:

    https://<workspace>-<user>.c9users.io/vnc.html

    When noVNC asks for connection details, you can connect with the pre-filled hostname <workspace><-<user>.c9users.io port 443 and password set in the earlier step, s3cr3t3 in your example.

    From the Cloud8 IDE workspace you can now open applications which draw to the VNC server and are visible through noVNC. For example:

    env DISPLAY=:99 xterm

    Reference: https://docs.c9.io/v1.0/docs/multiple-ports