在 Linux (Servicemix) 下运行时,在工作表上调用 autoSizeColumn 时崩溃 [英] Crash when calling autoSizeColumn on worksheet, when run under Linux (Servicemix)

查看:43
本文介绍了在 Linux (Servicemix) 下运行时,在工作表上调用 autoSizeColumn 时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了生成 excel 的模块,并将其部署在 Servicemix 下.在 Windows 环境中一切正常,但在 Linux 下 Servicemix 在以下调用时意外崩溃:

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);
    }

我使用的是 POI 版本 4.2-FINAL、FuseESB 4.2、Java 5.0.但是,没有 hs_err*.pid 文件.Servicemix 日志在第一次 autoSizeColumn 调用时结束.

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?

推荐答案

为了能够计算列宽,POI 需要掌握正在使用的 Font,并要求它依次调整每个字符的大小.在我所知道的所有 JVM 上,这都需要图形环境,因为实际工作由 JVM 委托给底层图形系统.

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.

如果您使用的是 Windows,那么您总是有一个图形系统,所以没问题.在 Linux 上,如果您在服务器上的命令行上运行,则可能不会.(Linux 作为桌面还是不错的)

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)

如果您在 Linux 服务器上运行而没有运行 X 服务器,则需要告诉 Java 运行无头".取自 POI AutoSize 文档

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

要计算列宽 Sheet.autoSizeColumn 使用 Java2D 类,如果图形环境不可用,则会抛出异常.如果图形环境不可用,您必须告诉 Java 您正在无头模式下运行并设置以下系统属性:java.awt.headless=true

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

尝试设置在您启动 JVM 时,我预感它会解决您的问题(这很可能是由于 Java 没有找到完整的图形环境造成的)

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)

这篇关于在 Linux (Servicemix) 下运行时,在工作表上调用 autoSizeColumn 时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆