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:
我编写了生成excel的模块,并在Servicemix下部署了它。在Windows环境中一切都很好,但在Linux Servicemix下意外崩溃后续调用:
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.
我正在使用POI版本4.2-FINAL,FuseESB 4.2,Java 5.0。但是,没有hs_err * .pid文件。 Servicemix日志在第一次autoSizeColumn调用结束。
Did anyone met such behaviour and know, how it is caused and how to come this around?
有没有人遇到过这种行为并且知道它是如何引起的以及如何解决这个问题?
2 个解决方案
#1
4
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.
为了能够计算列宽,POI需要保持正在使用的Font,并要求它依次调整每个字符的大小。在我所知道的所有JVM上,这需要一个图形环境,因为实际工作由JVM委托给底层图形系统。
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)
如果你在Windows上,你总是有一个图形系统,所以没关系。在Linux上,如果您在服务器上的命令行上运行,则可能不会。 (虽然Linux作为桌面很好)
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
如果你在没有运行X服务器的Linux服务器上运行,你需要告诉Java运行“无头”。取自POI AutoSize文档
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
计算列宽Sheet.autoSizeColumn使用Java2D类,如果图形环境不可用则抛出异常。如果图形环境不可用,您必须告诉Java您正在无头模式下运行并设置以下系统属性: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)
尝试在启动JVM时设置它,并且我预感它将解决您的问题(这很可能是由于Java找不到完整的图形环境引起的)
#2
0
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.
嗨,我遇到了类似的问题。我没有任何崩溃,但在我的开发环境(Windows)中,autosizecolumn工作。在生产环境(类Unix)上它没有用。我把系统属性java.awt.headless = true但我仍然遇到了问题。我解决了这个解决方案,但我添加了所有Arial系列字体。希望它能帮助任何人。
#1
4
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.
为了能够计算列宽,POI需要保持正在使用的Font,并要求它依次调整每个字符的大小。在我所知道的所有JVM上,这需要一个图形环境,因为实际工作由JVM委托给底层图形系统。
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)
如果你在Windows上,你总是有一个图形系统,所以没关系。在Linux上,如果您在服务器上的命令行上运行,则可能不会。 (虽然Linux作为桌面很好)
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
如果你在没有运行X服务器的Linux服务器上运行,你需要告诉Java运行“无头”。取自POI AutoSize文档
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
计算列宽Sheet.autoSizeColumn使用Java2D类,如果图形环境不可用则抛出异常。如果图形环境不可用,您必须告诉Java您正在无头模式下运行并设置以下系统属性: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)
尝试在启动JVM时设置它,并且我预感它将解决您的问题(这很可能是由于Java找不到完整的图形环境引起的)
#2
0
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.
嗨,我遇到了类似的问题。我没有任何崩溃,但在我的开发环境(Windows)中,autosizecolumn工作。在生产环境(类Unix)上它没有用。我把系统属性java.awt.headless = true但我仍然遇到了问题。我解决了这个解决方案,但我添加了所有Arial系列字体。希望它能帮助任何人。