Caused by: java.awt.Headlessexception: No X11 DISPLAY variable was set, but this program performed an Operation which re

Asked

Viewed 1,346 times

3

When trying to run a report that contains a fixed image on an Amazon linux server. The exception appears below. Someone has already been through it ?

Caused by: 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:204) at 
java.awt.Window.<init>(Window.java:536) at java.awt.Frame.<init>
(Frame.java:420) at java.awt.Frame.<init>(Frame.java:385) at 
javax.swing.JFrame.<init>(JFrame.java:189) at 
net.sf.jasperreports.view.JasperViewer.<init>(JasperViewer.java:267) at 
net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:655) at 
net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:587) at 
net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:535) at 
util.report.ExecutorComprovante.execute(ExecutorComprovante.java:49) ... 51 
more
  • If I set Display with this command: export DISPLAY=:0.0 The Display exception changes and shows only Caused by: java.awt.Headlessexception at java.awt.Graphicsenvironment.checkHeadless(Graphicsenvironment.java:204) at java.awt.Window. <init>(Window.java:536) at java.awt.Frame. <init>(Frame.java:420) at java.awt.Frame. <init>(Frame.java:385) at javax.swing.Jframe. <init>(Jframe.java:189) at net.sf.jasperreports.view.Jasperviewer. <init>(Jasperviewer.java:267) at

  • Edit the question on the button Editarbelow the tags and complements.

  • Just to confirm, which distro are you using? Ubuntu? Amazon Linux?

2 answers

1

Jasper Reports uses some features of awt for image manipulation, but it does not require a "real" graphical environment to generate a report as nothing is actually sent to the display. To generate reports on servers without any graphical environment installed a workaround known is to run the JVM in mode headless, that is, initialize your application process (or container, application server, etc) with:

-Djava.awt.headless=true 

Source Jaspersoft Community - Setting JVM Options for Application Servers

1

Often this type of error occurs when some code running outside a graphical environment, as in your case, on a server, tries to run something that uses a graphics library.

A good try is to install a Java headless. In Ubuntu you would do something like:

sudo apt-get autoremove openjdk-7-jre-headless

Browser other questions tagged

You are not signed in. Login or sign up in order to post.