我正在使用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)
所以我尝试将字体安装为one other * answer suggests.,但这给了我一个新的错误stacktrace-
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”);在我打电话给蜡染的转码器之前.但这也会生成上述错误消息.我没有其他选择了.
我想念什么吗?我可以做些什么来增加更多背景信息吗?谢谢您的帮助.
解决方法:
我在我的maven pom.xml文件中添加了以下依赖关系,它似乎使该类可供使用:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-gvt</artifactId>
<version>1.7</version>
</dependency>
但是请注意,它映射的字体并不总是与MS核心字体具有相同的尺寸(阿拉伯字体,新罗马字体等),因此看起来可能像是块状字体或不同于它们要替换的字体.