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

会有一股神秘感。 提交于 2020-01-01 12:25:10

问题


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?


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/7412457/crash-when-calling-autosizecolumn-on-worksheet-when-run-under-linux-servicemix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!