X11 error with Java Screenshot agent running as a service
I have created a small Java Agent that run on boot as a service on a CentOS box (linux). I am trying to implement in to the agent a screen capture function, where a screenshot is taken every 10 seconds and sent to a directory.
I have managed to do this, and it runs fine when I run it when logged in as a user.
However when I start the log agent as a service, I get the following error:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
Now the only reason I can think this is happening is because when the log agent starts up on boot, there is no X session open, however it still does not work when I log in, maybe because the log agent is running as root, and I am logging in as a different user. Is there any way to make the Java Screen Capture Robot, just take screenshots of the default X11 session of the person who is logged in?