How to set or export display variable through java code?
<p>We are required to add <code>export DISPLAY=:0.0</code> in tomcat's startup file and batch server's startup file. This is to make java see the X11 Display libraries on Unix and run our applet. Without this export in the startup files, the applet throws a Headless Exception.</p>

<p>Though this explicit export makes the java applet run, it disrupts the other applications running on the server. Is there a way where I can make this <code>export DISPLAY=:0.0</code> run from within java code instead of adding it to startup files? And if it is possible, would that be a good approach?</p>

<p>I have already tried setting the system property to <code>-Djava.awt.headless=true</code> , but it didn't work. As the link given above <a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/" rel="nofollow">http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/</a> also says that setting headless=true would work only for few components like Canvas, Panel but it will not work for the top level components.</p>

<p>So I feel the only option left for me is using <code>export DISPLAY=:0.0</code>. This is making my applet work when set in the startup files but causes problem for other applications running in the server. So if anybody could help me to make <code>export DISPLAY=:0.0</code> work such that it doesn't interfere with other applications in the server. One way I thought was to export the display through code. </p>

<p>Any help would be highly appreciated.</p>
