在redhat服务器上使用java.awt.HeadlessException
时,我得到了Docx4jReplacedElementFactory
。有人知道解决办法吗?(除了运行xvfb)
我已经深入研究了堆栈跟踪,问题的根源是java.awt.GraphicsEnvironment.getDefaultScreenDevice()
,它在无头环境中运行时抛出异常。如文档所述:“throws:headlessexception-if isheadless()返回true”(请参阅java.awt.HeadlessException thrown from HeadlessGraphicsEnvironment.getDefaultScreenDevice上的注释)。
如果getDefaultScreenDevice
按指定方式工作,那么在使用docx4j时是否有其他方法可以避免这样做?
从org.docx4j.org.xhtmlrenderer.util.ImageUtil.getGraphicsConfiguration
的来源来看,我们看到:
private static GraphicsConfiguration getGraphicsConfiguration() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-> GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
return gc;
}
堆栈跟踪:
Cause details:
java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:82)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil.getGraphicsConfiguration(ImageUtil.java:119)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil.makeCompatible(ImageUtil.java:70)
at org.docx4j.org.xhtmlrenderer.swing.AWTFSImage.createImage(AWTFSImage.java:38)
at org.docx4j.org.xhtmlrenderer.swing.NaiveUserAgent.createImageResource(NaiveUserAgent.java:197)
at org.docx4j.org.xhtmlrenderer.swing.NaiveUserAgent.getImageResource(NaiveUserAgent.java:167)
at org.docx4j.org.xhtmlrenderer.docx.Docx4jReplacedElementFactory.createReplacedElement(Docx4jReplacedElementFactory.java:57)
[snip]
最佳答案