开发者

Crash when calling autoSizeColumn on worksheet, when run under Linux (Servicemix)

开发者 https://www.devze.com 2023-04-05 05:37 出处:网络
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:

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:

    f开发者_如何学Goor (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)


We haven't tested it as it's not released yet, but since POI 5.2.3 there's a boolean system property that could help: org.apache.poi.ss.ignoreMissingFontSystem

Instructs Apache POI to ignore some errors due to missing fonts and thus allows to perform more functionality even when no fonts are installed. Note: Some functionality will still not be possible as it cannot use default-values, e.g. rendering slides, drawing, ...


Hi I faced a similar problem. I didn't have any crash, but on my development environment (Windows) the autosizecolumn worked. On production environment (Unix-like) it didn't work. I put system property java.awt.headless=true but I had the problem still. I solved following this solution but I added all the Arial Family fonts. Hope it helps anyone.

0

精彩评论

暂无评论...
验证码 换一张
取 消