title: Call Swing Java application from PHP script
body: <p>I need to make a call of Swing Java application from PHP script in Linux. Java application use swing but its main frame is invisible, so after setting DISPLAY env. variable I was able to run it from tty2 (from terminal without x11). The problem is that I can't do the same from PHP script. I use the following snippet:</p>
  
  <pre><code>$sys = system("export DISPLAY=:0.0", $output);
  $sys = system("java -jar scheduler.jar -i7.txt -q2 -a6 -s -e ", $output);
  </code></pre>
  
  <p>And I'm getting the following in /var/log/apache2/error.log:</p>
  
  <pre><code>    Exception in thread "main" java.awt.HeadlessException
  at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
  at java.awt.Window.&lt;init&gt;(Window.java:432)
  at java.awt.Frame.&lt;init&gt;(Frame.java:403)
  at java.awt.Frame.&lt;init&gt;(Frame.java:368)
  at javax.swing.JFrame.&lt;init&gt;(JFrame.java:158)
  at net.sukharevd.cssw.scheduler.view.AppFrame.&lt;init&gt;(AppFrame.java:51)
  at net.sukharevd.cssw.scheduler.Main.main(Main.java:11)
  </code></pre>
  
  <p>Also I tried to add -Djava.awt.headless=true parameter after <code>java</code>, but without success:</p>
  
  <pre><code>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:159)
  at java.awt.Window.&lt;init&gt;(Window.java:432)
  at java.awt.Frame.&lt;init&gt;(Frame.java:403)
  at java.awt.Frame.&lt;init&gt;(Frame.java:368)
  at javax.swing.JFrame.&lt;init&gt;(JFrame.java:158)
  at net.sukharevd.cssw.scheduler.view.AppFrame.&lt;init&gt;(AppFrame.java:51)
  at net.sukharevd.cssw.scheduler.Main.main(Main.java:11)
  </code></pre>
  
  <p>Help me to make Java application execute from PHP in the proper way.</p>