我正在使用 AWS Elasti Beanstalk 为我的一个应用程序供电。在此我需要将 svg 文档导出为 png、jpg、pdf 等。为此,我使用 Apache Batik 库。这在我的本地开发工作站上提供了出色的输出,但是一旦我在 EBS 上部署它,我就会开始收到错误,所有这些都与字体有关。
错误堆栈跟踪是 -
Caused by: java.lang.Error: Probable fatal error:No fonts found.
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1088)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:960)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:899)
at sun.font.FontManager.findDeferredFont(FontManager.java:916)
...
at sun.font.FontManager.findFont2D(FontManager.java:1904)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:792)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:468)
at sun.awt.X11GraphicsEnvironment.loadFonts(X11GraphicsEnvironment.java:925)
at sun.java2d.SunGraphicsEnvironment.loadFontFiles(SunGraphicsEnvironment.java:498)
at sun.java2d.SunGraphicsEnvironment.getInstalledFontFamilyNames(SunGraphicsEnvironment.java:721)
at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:746)
at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:773)
at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:99)
at org.apache.batik.gvt.font.FontFamilyResolver.(FontFamilyResolver.java:74)
at org.apache.batik.bridge.SVGTextElementBridge.getFontList(SVGTextElementBridge.java:1529)
at org.apache.batik.bridge.SVGTextElementBridge.getAttributeMap(SVGTextElementBridge.java:1610)
at org.apache.batik.bridge.SVGTextElementBridge.fillAttributedStringBuffer(SVGTextElementBridge.java:902)
at org.apache.batik.bridge.SVGTextElementBridge.buildAttributedString(SVGTextElementBridge.java:856)
at org.apache.batik.bridge.SVGTextElementBridge.computeLaidoutText(SVGTextElementBridge.java:636)
at org.apache.batik.bridge.SVGTextElementBridge.buildGraphicsNode(SVGTextElementBridge.java:292)
at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:224)
at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:82)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:208)
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:92)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
因此,我尝试按照另一个 stackoverflow 答案的建议安装字体。但这给了我一个新的错误堆栈跟踪-
Caused by: java.lang.NoClassDefFoundError:
Could not initialize class org.apache.batik.gvt.font.FontFamilyResolver
at org.apache.batik.bridge.SVGTextElementBridge.getFontList(Unknown Source)
at org.apache.batik.bridge.SVGTextElementBridge.getAttributeMap(Unknown Source)
at org.apache.batik.bridge.SVGTextElementBridge.fillAttributedStringBuffer(Unknown Source)
at org.apache.batik.bridge.SVGTextElementBridge.buildAttributedString(Unknown Source)
at org.apache.batik.bridge.SVGTextElementBridge.computeLaidoutText(Unknown Source)
at org.apache.batik.bridge.SVGTextElementBridge.buildGraphicsNode(Unknown Source)
at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
我不明白为什么会这样。然后我System.setProperty("java.awt.headless", "true");
在调用 batik 的转码器之前进行设置。但这也会产生上述错误信息。我的选择已经不多了。
我错过了什么吗?我可以做些什么来为此添加更多上下文吗?谢谢您的帮助。