在 Linux (Servicemix) 下运行时,在工作表上调用 autoSizeColumn 时发生崩溃
我编写了生成Excel的模块,并在ServiceMix下部署了它。在Windows环境中,一切都很好,但是在Linux ServiceMix下,会出乎意料地崩溃:
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'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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了能够计算列宽度,POI需要保留使用中的字体,并要求它依次尺寸每个字符。在我所知道的所有JVM上,这都需要一个图形环境,因为实际工作由JVM委派给基础图形系统。
如果您在Windows上,您始终拥有一个图形系统,所以很好。在Linux上,如果您在服务器上的命令行上运行,则可能不会。 (虽然Linux作为台式机很好)
如果您在没有X服务器运行的Linux服务器上运行,则需要告诉Java运行“无头”。从 poi自动化文档
尝试设置启动JVM时,我的预感会解决您的问题(这很可能是由Java引起的,找不到完整的图形环境)
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
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)
我们尚未测试它,因为它尚未发布,但自 POI 5.2.3 以来,有一个布尔系统属性可以提供帮助:
org.apache.poi.ss.ignoreMissingFontSystem
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
嗨,我遇到了类似的问题。我没有发生任何崩溃,但在我的开发环境(Windows)上,autosizecolumn 起作用了。在生产环境(类Unix)上它不起作用。我设置了系统属性 java.awt.headless=true 但问题仍然存在。我解决了以下 这个解决方案,但我添加了所有 Arial Family 字体。希望它对任何人都有帮助。
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.
我在迁移服务器(OpenJDK 1.8、Rocky Linux 9)时遇到了同样的问题,
无头设置对我没有帮助(
java.awt.headless=true
)。但安装 fontconfig 解决了这个问题。我假设这个包带有默认字体。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.