问题
I am using AWS Elasti Beanstalk to power one of my apps. In this I need to export a svg document to png,jpg, pdf etc. For this I use Apache Batik library. This provides excellent output on my local dev workstation but as soon as I deploy it on the EBS I start getting errors, all related to fonts.
The error stacktrace was -
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)
So I tried installing fonts as one other stackoverflow answer suggests. But this gave me a new error 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)
I dont understand why is this happening. Then I set System.setProperty("java.awt.headless", "true");
just before I make a call to batik's transcoder. But this also generate the above error message. I am running out of options.
Am I missing something? Can I do anything to add more context to this? Thanks for the help.
回答1:
I added the following dependency to my maven pom.xml file, and it seems to have made the class available for use:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-gvt</artifactId>
<version>1.7</version>
</dependency>
Note, however, that the fonts that it maps to don't always have the same dimensions as the MS core fonts (arial, times new roman, etc.) so can look kind of blocky or different than the ones they're replacing.
回答2:
I finally resolved this problem by installing Sun JDK & using it to power my tomcat server.
来源:https://stackoverflow.com/questions/7940455/having-problems-with-apache-batik-library-on-aws-elasticbeanstalk-instance