title: Unable to open DISPLAY with JavaFX on ubuntu server
body: <p>I have a simple Application which generates a png of a chart which is based on JavaFX. The app fails to run on displayless machine with the following exception, I don't need to render or display content on the console, just need to create the image.</p>
  
  <pre><code>"main" java.lang.UnsupportedOperationException: Unable to open DISPLAY
      at com.sun.glass.ui.gtk.GtkApplication.&lt;init&gt;(GtkApplication.java:68)
      at com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
      at com.sun.glass.ui.Application.run(Application.java:146)
      at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
      at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
      at javafx.embed.swing.JFXPanel.initFx(JFXPanel.java:215)
      at javafx.embed.swing.JFXPanel.&lt;init&gt;(JFXPanel.java:230)
  </code></pre>
  
  <p>I'm trying to run this on a AWS instance. Is there a way to overcome this issue? Following is my sample code.</p>
  
  <pre><code>import javafx.application.Platform;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.embed.swing.JFXPanel;
  import javafx.embed.swing.SwingFXUtils;
  import javafx.scene.Scene;
  import javafx.scene.chart.PieChart;
  import javafx.scene.image.WritableImage;
  import javafx.stage.Stage;
  
  import java.io.File;
  import java.io.IOException;
  import java.nio.file.Paths;
  import javax.imageio.ImageIO;
  
  public class Test {
  
      public static void main(String[] args) {
  
          String chartGenLocation = "/Users/tmp";
          new JFXPanel();
          ObservableList&lt;PieChart.Data&gt; pieChartData =
                  FXCollections.observableArrayList(
                          new PieChart.Data("Failed", 10),
                          new PieChart.Data("Skipped", 20));
          final PieChart chart = new PieChart(pieChartData);
          chart.setAnimated(false);
          Platform.runLater(() -&gt; {
              Stage stage = new Stage();
              Scene scene = new Scene(chart, 500, 500);
              stage.setScene(scene);
              WritableImage img = new WritableImage(500, 500);
              scene.snapshot(img);
  
              File file = new File(Paths.get(chartGenLocation, "a.png").toString());
              try {
                  ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", file);
              } catch (IOException e) {
                  //logger.error("Error occurred while writing the chart image
              }
          });
      }
  }
  </code></pre>
  
  <p>I have seen few SO answers which mostly talk about monocle and testfx, here I'm unable to add external dependencies. So adding testfx is not a option. I have also tried the following with xvbf, which hangs the system,</p>
  
  <pre><code>Xvfb :95 -screen 0 1024x768x16 &amp;&gt; xvfb.log &amp;
  export DISPLAY=:95.0
  </code></pre>
  
  <p>When I execute I see the following output and system hangs there.</p>
  
  <pre><code>(process:13112): Gtk-WARNING **: Locale not supported by C library.
      Using the fallback 'C' locale.
  Fontconfig warning: ignoring UTF-8: not a valid region tag
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Execution Sequence</p>
  
  <pre><code>Xvfb :92 -screen 0 1024x768x16 &amp;&gt; xvfb.log &amp;
  export DISPLAY=:92.0
  </code></pre>
  
  <p>No errors in xvbf.log, seems to start properly.</p>
  
  <pre><code>java Test
  </code></pre>
  
  <p>I see following in console out</p>
  
  <pre><code>(process:13356): Gtk-WARNING **: Locale not supported by C library.
      Using the fallback 'C' locale.
  Fontconfig warning: ignoring UTF-8: not a valid region tag
  </code></pre>
  
  <p>I do not see any log in xvbf.log, the execution doesn't proceed after the above log. My image is not getting generated.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>I would like to know if there is a way to bypass <a href="https://github.com/loveyoupeng/rt/blob/master/modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java#L67" rel="nofollow noreferrer">this validation</a> since I really don't need a display rendering. </p>