英文:
Font is not available to the JVM with Jasper Reports in Docker Container
问题
我正在尝试在Docker容器中使用DynamicJasper生成报表。
如果我遇到以下错误:
net.sf.jasperreports.engine.util.JRFontNotFoundException:
字体'Arial'对JVM不可用。
我该如何解决这个问题?
英文:
I'm trying to generate a report with DynamicJasper in Docker container?
If I get the followfing error:
net.sf.jasperreports.engine.util.JRFontNotFoundException:
Font 'Arial' is not available to the JVM.
How can I fix this?
答案1
得分: 3
我使用了类似下面的 Dockerfile,问题得以解决。
我尝试在容器中的文件系统中搜索字体,使用以下命令:
ls /usr/share/fonts/truetype/msttcorefonts/
我可以看到字体加载在这个文件夹中。
FROM openjdk:8u141-jre
COPY /build/libs/my-app*.jar /my-app.jar
EXPOSE 9500
RUN apt-get update && apt-get install -y vim
RUN echo "deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" | tee /etc/apt/sources.list.d/multiverse.list
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN ["apt-get", "-y", "install", "ttf-mscorefonts-installer"]
RUN dpkg-reconfigure ttf-mscorefonts-installer
RUN apt-get install -y apt-transport-https apt-utils
RUN apt-get install --reinstall -y ttf-mscorefonts-installer
CMD java -XX:+PrintFlagsFinal $JAVA_OPTS -jar /my-app.jar
英文:
I used a Dockerfile like the one below and the problem was solved.
I tried searching for the font in the filesystem in container, with:
ls /usr/share/fonts/truetype/msttcorefonts/
I can see the fonts loaded the folder.
FROM openjdk:8u141-jre
COPY /build/libs/my-app*.jar /my-app.jar
EXPOSE 9500
RUN apt-get update && apt-get install -y vim
RUN echo "deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" | tee /etc/apt/sources.list.d/multiverse.list
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN ["apt-get", "-y", "install", "ttf-mscorefonts-installer"]
RUN dpkg-reconfigure ttf-mscorefonts-installer
RUN apt-get install -y apt-transport-https apt-utils
RUN apt-get install --reinstall -y ttf-mscorefonts-installer
CMD java -XX:+PrintFlagsFinal $JAVA_OPTS -jar /my-app.jar
答案2
得分: 2
以下是翻译好的内容:
实际上,JVM本身不包含任何字体。这就是为什么您需要自己安装它们。您的解决方案似乎已经很好。对于基于Debian的Docker镜像,我执行以下操作:
#添加非自由存储库以获取微软字体
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
RUN apt-add-repository contrib
RUN apt-get update
#如果您想在报告中使用Microsoft字体,必须安装字体
#Andale Mono、Arial Black、Arial、Comic Sans MS、Courier New、Georgia、Impact、
#Times New Roman、Trebuchet、Verdana、Webdings)
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
ADD localfonts.conf /etc/fonts/local.conf
RUN fc-cache -f -v
#如果您想要使用特殊字符,比如汉字,您必须安装一个支持它们的字体
#例如:
RUN apt install -y fonts-wqy-zenhei
localfonts.conf文件是为调整'msttcorefonts'集合的一些抗锯齿规则而优化的。您可以在此处找到它:https://wiki.ubuntu.com/Fonts#Manual_Font_Smoothing
不幸的是,文件长度太长,无法在SO上共享,但可以合理地假设我发布的链接将保存在Ubuntu维基上。
英文:
Essentially, the JVM itself does not hold any font. That's why you have to install them by yourself. Your solution seems already good. For Debian-based Docker images I do the following:
#Add non-free repositories to get MS fonts
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
RUN apt-add-repository contrib
RUN apt-get update
# If you want to use Microsoft fonts in reports, you must install the fonts
# Andale Mono, Arial Black, Arial, Comic Sans MS, Courier New, Georgia, Impact,
# Times New Roman, Trebuchet, Verdana,Webdings)
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
ADD localfonts.conf /etc/fonts/local.conf
RUN fc-cache -f -v
# If you want to use special characters, such as chinese ideograms, you must install a
font that support them
# For example:
RUN apt install -y fonts-wqy-zenhei
The localfonts.conf file is an optimized for tweaking some anti-aliasing rules for the 'msttcorefonts' collection. Yo can find it here: https://wiki.ubuntu.com/Fonts#Manual_Font_Smoothing
Unfortunatly the file length is too file to share it on SO, but it's resonable to suppose that the link I posted will be kept on Ubuntu wiki.
答案3
得分: 0
这帮助我解决了关于我的基于Debian的Docker镜像的问题:
RUN apt-get -q update \
&& apt-get -q install -y cabextract libmspack0 \
&& wget http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
&& dpkg -i ttf-mscorefonts-installer_3.6_all.deb
英文:
This helped me with my Debian-based Docker image
RUN apt-get -q update \
&& apt-get -q install -y cabextract libmspack0 \
&& wget http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb \
&& dpkg -i ttf-mscorefonts-installer_3.6_all.deb
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论