Ok let me explain this in detail. And the server and clients are not on the same machine. The tomcat server is run on one machine, the batch server is a separate machine and there are several client machines.
Tomcat Server:
I added export DISPLAY=:0.0
in tomcat's startup.sh file. This removes the X11 Display error and the Headless Exception and my code works. Since tomcat is run in a separate instance, it is not affecting other applications running out of tomcat on that machine. Hence there is no side effects here.
Batch Server:
I added export DISPLAY=:0.0
in batch server's batchstart.sh file. This also removes the X11 Display error and the Headless Exception and my code works. But here batchstart.sh file is sourced for the entire batch server. So all the other applications running on batch server use the settings of this file. All other applications are able to see the X11 Display except mine, which till java 1.4 was also working without any X11 Display error. The problem started only after I moved my app to java 1.5. When I set the export DISPLAY=:0.0
in batch server's batchstart.sh file, it overrides the existing Display that is being used by other applications and hence causes problems for the other applications running.
Any help highly appreciated.