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

4

5

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?

Laager answered 14/9, 2011 at 7:1 Comment(0)
G
6

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)

Gustaf answered 14/9, 2011 at 9:15 Comment(0)
P
2

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, ...

Poseidon answered 5/8, 2022 at 8:1 Comment(1)
I tried using it but this is not helpingDistress
A
1

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.

Astonishing answered 20/9, 2012 at 16:36 Comment(2)
Unfortunately, it does not as the link is no longer valid. That is why it is recommended to avoid using links to avoid an actual explanationMide
wayback machine to the rescue! web.archive.org/web/20190905110215/http://…Poseidon
K
0

I faced the same issue while migrating servers (OpenJDK 1.8, Rocky Linux 9)

The headless settings didn't help me (java.awt.headless=true). But installing fontconfig solved the problem. I assume this package is coming with default fonts.

$> sudo dnf install fontconfig
$> fc-list
Kim answered 7/12, 2023 at 1:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.