title: Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable
body: <p>I have trouble running a Java application in my CentOS server. When I fire the command below:</p>
  
  <pre><code>java -jar the-application.jar
  </code></pre>
  
  <p>I receive the following error:</p>
  
  <pre><code>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.&lt;init&gt;(Window.java:535)
  at java.awt.Frame.&lt;init&gt;(Frame.java:420)
  at java.awt.Frame.&lt;init&gt;(Frame.java:385)
  at javax.swing.JFrame.&lt;init&gt;(JFrame.java:174)
  at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745)
  at java.awt.EventQueue.access$300(EventQueue.java:103)
  at java.awt.EventQueue$3.run(EventQueue.java:706)
  at java.awt.EventQueue$3.run(EventQueue.java:704)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:715)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:218)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:133)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:122)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:118)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:110)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
  </code></pre>
  
  <p>I tried to define DISPLAY variable using command below, but this time only the error changed and the command failed again:</p>
  
  <p>Command to set DISPLAY variable:</p>
  
  <pre><code>export DISPLAY=:0.0
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
  </code></pre>
  
  <p>Based on the recommendations from different forums, I also tried the followeing varibales separately, but there was no luck:</p>
  
  <pre><code>export DISPLAY=:0
  export DISPLAY=:99
  export DISPLAY=:99.0
  export DISPLAY=:1
  export DISPLAY=:1.0
  export DISPLAY=127.0.0.1:0
  export DISPLAY=127.0.0.1:0.0
  export DISPLAY=127.0.0.1:99
  export DISPLAY=127.0.0.1:99.0
  export DISPLAY=127.0.0.1:1
  export DISPLAY=127.0.0.1:1.0
  </code></pre>
  
  <p>I tried "xhost + localhost" command, so that maybe it can help, however, I receive the error below:</p>
  
  <pre><code>-bash: xhost: command not found
  </code></pre>
  
  <p>Can anyone help me resolve this issue? Thank you all in advance.</p>