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 5.2.7.63 (1.0.0.68 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(Class.java:264)
	at java.awt.Toolkit$2.run(Toolkit.java:860)
	at java.awt.Toolkit$2.run(Toolkit.java:855)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
	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(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.lucee.extension.pdf.pd4ml.PDFByReflection.invoke(PDFByReflection.java:228)
	at org.lucee.extension.pdf.pd4ml.PDFByReflection.render(PDFByReflection.java:199)
	at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument.content(PD4MLPDFDocument.java:148)
	at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument.render(PD4MLPDFDocument.java:120)
	at org.lucee.extension.pdf.tag.Document.render(Document.java:727)
	at org.lucee.extension.pdf.tag.Document._doEndTag(Document.java:637)
	at org.lucee.extension.pdf.tag.Document.doEndTag(Document.java:574)
	at __138.views.events.bookings.show_pdf_cfm230$cf.c

VHost Config:

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

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

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

</VirtualHost>

I suspect https://dev.lucee.org/t/cfdocument-creates-0-length-file/ 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/setenv.sh, 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).
T