Cfdocument: Could not initialize class sun.awt.X11.XToolkit

Hi All;
Would really appreciate any help people might be able to give to point me in the correct direction with this one.
When trying to use cfdocument I’m getting Could not initialize class sun.awt.X11.XToolkit.

The code works fine locally, and in fact worked fine on this particular server when lucee was running out of /opt/lucee/tomcat/webapps/ROOT/ - however, we’ve now changed it so that Apache is properly proxying the requests, and there’s some sort of issue preventing the PDF from being created.

Environment details:
Lucee ( pdf extension: tried with older versions, no joy)
Apache/2.4.18 (Ubuntu)
Lucee running as user lucee, Apache running as www-data.
All Files in /opt/lucee/ and /var/www/domain owned by lucee:lucee.
www-data is in the lucee group. All permissions set to 0775

lucee.runtime.exp.NativeException: Could not initialize class sun.awt.X11.XToolkit
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at java.awt.Toolkit$
	at java.awt.Toolkit$
	at Method)
	at java.awt.Toolkit.getDefaultToolkit(
	at org.zefer.font.c.<init>(Unknown Source)
	at org.zefer.cache.ResourceCache.getFontMetrics(Unknown Source)
	at org.zefer.html.doc.q.?00000(Unknown Source)
	at org.zefer.html.doc.q.return(Unknown Source)
	at org.zefer.html.doc.w.<init>(Unknown Source)
	at org.zefer.html.doc.PD4MLHtmlParser.buildDocument(Unknown Source)
	at org.zefer.pd4ml.PD4ML.o00000(Unknown Source)
	at org.zefer.pd4ml.PD4ML.render(Unknown Source)
	at org.zefer.pd4ml.PD4ML.render(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.lucee.extension.pdf.pd4ml.PDFByReflection.invoke(
	at org.lucee.extension.pdf.pd4ml.PDFByReflection.render(
	at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument.content(
	at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument.render(
	at org.lucee.extension.pdf.tag.Document.render(
	at org.lucee.extension.pdf.tag.Document._doEndTag(
	at org.lucee.extension.pdf.tag.Document.doEndTag(

VHost Config:

<VirtualHost *:80>
	DocumentRoot /var/www/domain/ 
    	DirectoryIndex index.cfm index.html
 	<Directory "/var/www/domain/">
    		Options Indexes FollowSymLinks
        	AllowOverride All
        	Require all granted 
	LogHeaders false
	LogHandlers false
	LogAliases false
	VDirHeader false

	CFMLHandlers ".cfm .cfc .cfml"
	ModCFML_SharedKey "redacted...etc.etc.."

	<IfModule mod_proxy.c>
	<Proxy *>
	Allow from
	ProxyPreserveHost On
	ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$$1$2
	ProxyPassMatch ^/(.+\.cfchart)(/.*)?$$1$2
	ProxyPassMatch ^/(.+\.cfml)(/.*)?$$1$2 
	ProxyPassReverse /


I suspect is a similar issue, but there’s no solution there except a hint at permissions.

Any ideas how I can get further on debugging this?

I have no idea why this behavior would be different after your web server topology change, but I have a couple of ideas you can look into.

  1. You may need to put the JVM running your Lucee in “headless mode”. On my Linux Lucee servers, I think the right way to accomplish this is to edit /opt/lucee/tomcat/bin/, adding -Djava.awt.headless=true to the CATALINA_OPTS variable. E.g., changing this:
    CATALINA_OPTS="-Xms256m -Xmx512m";
    to this:
    CATALINA_OPTS="-Xms256m -Xmx512m -Djava.awt.headless=true";
    (Page where I got this idea).
  2. If #1 doesn’t work, there might be some GUI libraries that your server is missing. I’m not sure what they would be, exactly.
1 Like

Amazing - that’s fixed it!
Many many thanks! (had me properly stumped that one).