I've written module that generates excel, and deployed it under Servicemix. In Windows environment everything is fine, but under Linux Servicemix unexpectedly crashes on following call:
for (short i=0;i<=3;i++) {
log.trace("AutoSize column {}", i);
worksheet.autoSizeColumn(i);
}
I'm using POI version 4.2-FINAL, FuseESB 4.2, Java 5.0. There are, however, no hs_err*.pid files. Servicemix logs ends on first autoSizeColumn call.
Did anyone met such behaviour and know, how it is caused and how to come this around?
In order to be able to calculate the column widths, POI needs to get hold of the Font in use, and ask it to size each character in turn. On all JVMs that I know of, this requires a graphical environment, because the actual work is delegated by the JVM to the underlying graphical system.
If you're on Windows, you always have a graphical system so that's fine. On Linux, if you're running on the command line on a server, you may not. (Linux as a desktop is fine though)
If you are running on a linux server without an X server running, you'll need to tell Java to run "headless". As taken from the POI AutoSize documentation
To calculate column width Sheet.autoSizeColumn uses Java2D classes that throw exception if graphical environment is not available. In case if graphical environment is not available, you must tell Java that you are running in headless mode and set the following system property: java.awt.headless=true
Try setting that when you start your JVM, and I've a hunch it'll fix your issue (which is most likely caused by Java not finding a complete graphical environment)