0

I am doing screen recording application in servlet. But its working correctly in localhost with tomcat sever7x. But when I hosted in web server it shows error like this

java.awt.AWTException: headless environment     at java.awt.Robot.(Robot.java:94)

Can any one help me? Thanks.

Alexey Malev
  • 6,408
  • 4
  • 34
  • 52
user3607151
  • 19
  • 1
  • 2
  • Did you find solution for this? @user3607151 – Sachin HR Mar 21 '19 at 04:59
  • This is a huge http://xyproblem.info. The abovelinked duplicate answers the X. Your attempted solution (the Y) is in no way going to work for the very simple reason that in real production environment the server machine (where your Java code runs) is a **physically different** machine than the client machine (where the webbrowser runs). You're basically trying to grab the screenshot of the screen attached to the server machine not the client machine. But normally production servers don't have any screen attached. They're only the same machine at localhost. That's why it then seems to "work". – BalusC Dec 14 '20 at 10:08

3 Answers3

1

this is not clear to me, are you trying to capture the server's screen? as you are using servlet?!

i think its related to display issues on the server because most servers does not have GUI (Gnome or desktop) as windows for example

so thats your problem

also have a look at this post

Headless environment error in java.awt.Robot class with MAC OS

last post by Ginger Head

Community
  • 1
  • 1
Yazan
  • 6,074
  • 1
  • 19
  • 33
  • thank u for ur reply .i need to capture the screen on the browser only not server. But the thing its not recording when i hosted into the jsp hosting server. Do u know any any name of the server having GUI .. thanx – user3607151 May 06 '14 at 09:22
0

This exception is happening because you're using some API that requires environment to support graphics (if saying that simplified). In order to resolve issue you have to either get rid of using classes that requires graphics support, or run it at not headless environment. Try taking a look at line 94 of Robot.java to find out what API complains on headless environment.

You may find these links useful:

What does "headless" mean?

http://www.oracle.com/technetwork/articles/javase/headless-136834.html

Community
  • 1
  • 1
Alexey Malev
  • 6,408
  • 4
  • 34
  • 52
0

I got this problem while running Selenium test(configured to use remote server) on Jenkins. Solution for mwe was to start Xvfb Plugin before the job: https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin

Horatiu
  • 375
  • 3
  • 6