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

Question:

When trying to run a report containing a still image on an Amazon linux server. The exception below appears. Has anyone ever experienced this ?

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

Answer:

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

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

sudo apt-get autoremove openjdk-7-jre-headless
Scroll to Top